postman学习
postman介绍
Authorization Headers Body Pre-request Script Test
认证接口 请求报文头 请求体 预置条件,请求发送之前优先执行该部分代码,支持js,清空环境变量等 检查点,断言
Test中公式用法
格式 tests[“检查点说明”] === 布尔表达式
Status
Status code:Code is 200
响应状态码 200:http请求是通的
eg:
pm.test(“Status code is 200”, function () {
pm.response.to.have.status(200);
});
pm.test(“Status code is 200”, function () {
pm.response.to.have.status(400);
});
Status code:Code name has string
响应状态码包含字符串
eg:
pm.test(“Status code name has string”, function () {
pm.response.to.have.status(“OK”);
});
Response
Response time is less than 200ms
响应状态时间,性能指标,响应状态时间小于200ms
eg.
pm.test(“Response time is less than 200ms”, function () {
pm.expect(pm.response.responseTime).to.be.below(200);
});
Response body:Contains string
请求体包含字符串
eg.
pm.test(“Body matches string”, function () {
pm.expect(pm.response.text()).to.include(“北京”);
});
Response body:is equal to a string
值等于
eg.
pm.test(“Body is correct”, function () {
pm.response.to.have.body(“北京”);
});
Response body:Convert XML body to a JSON Object
转成json格式
eg.
var jsonObject = xml2Json(responseBody);
Response body:JSON value check
校验json文件格式 调用通过 父节点.子节点、父节点[子节
eg.
pm.test(“Your test name”, function () {
var jsonData = pm.response.json();
pm.expect(jsonData.value).to.eql(100);
});
全局变量、项目环境变量
Set an environment variable
Set a global variabel
eg.
var code =’***’
pm.globals.set(“city_code”, code);var jsonObject = xml2Json(responseBody);
在使用过程中需要选择环境变量
断言外引用 :{{XXX}}
断言中引用 :envieonment[‘XXX’] globals[‘XXX’]
console
可供调试的工具,使用方法 console.log()
所处位置:view-show Postman Console
Runner
可批量执行用例的工具
Environment:选择环境变量
Iteraions:用例循环次数
Delay:间隔时间,用例与用例间的间隔时间
实际应用:
使用接口页面:http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?op=getSupportCityString
Get请求:
1、选择Get方法;2、填写url;3、填写Params参数进行参数传递;4、点击send获取结果
POST请求:
1、选择POST方法;2、填写url;3、填写body内容,选择请求正文格式,填写请求参数;4、点击send获取结果
SOAP协议请求:
1、选择POST方法;2、填写url;3、填写body内容,选择请求正文格式为raw,选择XML(text\xml),在body主题内填入请求数据;4,、点击send获取结果