当前位置:网站首页>Postman自动化接口测试
Postman自动化接口测试
2022-06-26 12:55:00 【长不大的大灰狼】
Postman自动化接口测试
一、利用Swagger批量导入接口
(1)通过Swagger地址导入
File->import->import From Link(导入Swagger地址)
(2)通过Swagger接口文档导入
File->import->import File(导入Swagger接口文档 txt文本也可以)
(3)生成接口文档
二、基本使用
1、编写参数及断言
Params
: 用来配置基本的参数Headers
: 用来配置请求头参数Pre-request-Script
: 用来读取文件中的参数Tests
: 用来编写测试断言
Pre-request-Script的一般用法:
let baseUrl = pm.iterationData.get('baseUrl')
let userName = pm.iterationData.get('userName')
let page = pm.iterationData.get('page')
let size = pm.iterationData.get('size')
pm.environment.set('userName',userName) //用于配置请求头
pm.environment.set('baseUrl',baseUrl) //用于配置基础路径
pm.variables.set('page',page) //用于配置普通参数,或者路径参数
pm.variables.set('size',size)
Tests断言的一般用法:
//测试返回的json是否与预期的json相等,如果相等则通过测试
pm.test("测试结果",function(){
var jsonData = pm.response.json();
pm.expect(jsonData).to.eql({
"name": "武松",
"gender": "1"
})
})
或者
//测试返回的状态码是否为200,如果是,则通过测试
pm.test("测试结果",function(){
pm.response.to.have.status(200);
})
注意:
读取文件中的参数值,参数需要用{ {参数名}}
包起来;
2、配置文件参数
参数文件需要采用csv格式:
表中的一条记录就是调用一次接口对应的参数;
3、进行接口测试
选中要测试的接口,点击Runner:
选取参数文件,Start Run开始测试:
边栏推荐
- Solutions to insufficient display permissions of find and Du -sh
- 12 SQL optimization schemes summarized by old drivers (very practical)
- A few lines of code can realize complex excel import and export. This tool class is really powerful!
- 微信小程序注册指引
- Mysql database explanation (6)
- Electron official docs series: Best Practices
- Included angle of 3D vector
- Aesthetic experience (episode 238) Luo Guozheng
- Basic type of typescript
- Beifu PLC based on NT_ Shutdown to realize automatic shutdown and restart of controller
猜你喜欢
What features are added to Photoshop 2022 23.4.1? Do you know anything
Here document interaction free and expect automatic interaction
基于PyTorch的生成对抗网络实战(7)——利用Pytorch搭建SGAN(Semi-Supervised GAN)生成手写数字并分类
Mediapipe gestures (hands)
Ring queue PHP
MySQL数据库讲解(三)
Lamp compilation and installation
Nexys A7开发板资源使用技巧
awk工具
[MySQL from introduction to mastery] [advanced part] (II) representation of MySQL directory structure and tables in the file system
随机推荐
网络远程访问的方式使用树莓派
12 SQL optimization schemes summarized by old drivers (very practical)
Arcpy - - utilisation de la fonction insertlayer (): ajout de calques dans un document de carte
Hdu1724[Simpson formula for integral]ellipse
Beifu PLC based on NT_ Shutdown to realize automatic shutdown and restart of controller
A primary multithreaded server model
Sed editor
[how to connect the network] Chapter 2 (Part 1): establish a connection, transmit data, and disconnect
awk工具
What is the use of index aliases in ES
GO语言-管道channel
ES中索引别名(alias)的到底有什么用
Uva5009 error curves three points
Here Document免交互及Expect自动化交互
Es sauvegarde et restauration des données par instantané
2. Introduction to parallel interface, protocol and related chips (8080, 8060)
MySQL数据库讲解(四)
Oplg: new generation cloud native observable best practices
遍历指定目录获取当前目录下指定后缀(如txt和ini)的文件名
Wechat applet -picker component is repackaged and the disabled attribute is added -- below