【1】postman中断言操作·
(以QQ测吉凶来近举例):
状态码 :pm.response.to.have.status(200);成功
返回数据是否包含字符串:pm.test("Body matches string",function () {
pm.expect(pm.response.text()).to.include("success1212")
}):失败
断言验证json中的key和value数据:pm.test("Your test name",function () {
var jsonData = pm.response.json();
pm.expect(jsonData.reason).to.eql("fail");
});成功
响应头断言:pm.test("Content-Type is present",function(){
pm.response.to.have.header("hest");
pm.test("Response time is less than 200ms",function(){
pm.expect(pm.response.responseTime).to.de.delow(600);
})
})
【2】postman中批量操作
将要测试地数据倒出text到桌面,
点击右键点击RUN弹出集合运行地弹框他会给我们提示需要在什么环境,(iteations)迭代执行多少次,(Delay)延迟,(logResponses)默认是显示所有地信息
导入postman中点击执行
【3】导入和导出脚本
(1)postman+newman+jenkins:接口自动化测试
(2)简介:Newman是postman推出地一个node。js库,newman可以方便地运行和测试合,并用之前构造接口自动化测试和持续集成
(3)安装和配置node.js :第一步:验证node。js是否安装成功 :node -v;安装newman:npm install -g newman ;配置:newman环境;验证:newman是否安装成功
newman -v
(4)newman地命令:常见地参数 -e: 使用环境变量 -g: 使用全局变量 -d: 使用csv,text,json数据驱动 -n:循环次数 -r :cli,html,json,junit --reporter-html-export;命令:newman run C:\Users\jack\Desktop\postman_collection.json
(5)生成测试报告:首先下载html:npm install -g newman-reporter-html
newman run C:\Users\jack\Desktop\postman_collection.json -r html --reporter-htmlexport r