接口测试工具postman

发布于:2024-10-11 ⋅ 阅读:(15) ⋅ 点赞:(0)

1、下载postman的安装包

2、下载好的安装包,点击打开

3、介绍postman

(1)左边 创建一个集合creat a new collection

(2)点击加号 创建接口

修改post或get请求方式   输入URL

body-网址  key:账号、请求体的入参参数:密码

(3)保存接口,存放到集合中

  (4)send 发送接口

创建了一个接口

(5)介绍整个页面详情

postman中的功能

1、切换主题setting -themes

2、添加环境变量(右上角) -manage environments

3、添加一个post接口和get接口

(1)fiddler抓取后 post接口(centent-type键值)

入参格式:

body

form-data是web表单默认的传输格式,编辑器允许你通过设置key-value形式的数据来模拟填充表单,你可以在最后的选项中选择添加文件。x-www-form-urlencoded:编码格式通过设置key-value的方式作为URL的参数

raw:一个raw请求可以包含任何内容,在这里你可以设置我们常用的JSON和XML数据格式
binary:上传发送视频、音频、图片、文本等文m

(2)get接口 需要用?拼接

4、设置变量

{{变量名}}  花括号: 变量

(1)引用的变量来自环境变量

a、添加环境变量:u,p

b、设置接口的变量

5、依赖接口

两个介接口以上:登录接口,查询用户接口(先登录才能查看用例)

1.登录接口,有了cookies

右上角写入参数

导入参数


登陆成功

没有依赖就形成HTML格式

6、断言

test  是断言

常用的断言响应时间、响应状态码、响应内容

pm.test("Status code is 200", function () {

    pm.response.to.have.status(200);

});

pm.test("Body matches string", function () {

    pm.expect(pm.response.text()).to.include("成功");

});

pm.test("Response time is less than 200ms", function () {

    pm.expect(pm.response.responseTime).to.be.below(200);

})

Get a wariable

Set an environment variable

set a global variable

Clear an environment variable

Clear a global variable

send a request

Status code: Code is 200

Response body: Contains string

Response body: JSON value check

Response body. Is equal to a string

Response headers: Content-Type header check

Response time is less than 200ms

Status code: Successful POST request

Status code: Code name has string

Response body: ConwertXML body to a ]SONobject

Use Tiny Validator for JSON data