1.首先安装node
2.安装 npm install -g newman
3.执行newman run PostMan.postman_collection.json --reporters html 在当前目录生成一个newman的文件夹,该文件下生成HTML报告
newman run PostMan.postman_collection.json --reporters html --reporter-html-export d:\htmlout.html
4.可以集成到jenkins上postman+newman+git+jenkins
test脚本地址https://learning.getpostman.com/docs/postman/scripts/test_scripts/
postman console的控制台输出 view --show postman console
/*HTTP状态码验证*/
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
//响应时间少于1000ms
pm.test("Response time is less than 1000ms", function () {
pm.expect(pm.response.responseTime).to.be.below(1000);
});
/*校验json返回值*/
pm.test("Your test name", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.meta.errno).to.eql(0);
});
/*校验json返回值*/
pm.test("Your test name", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.meta.msg).to.eql("success");
});
//提取返回值 存放到环境变量里 用{{errno}}来代替
var jsonData = pm.response.json()
pm.environment.set("errno", jsonData.meta.errno);
csv文件的参数化
1.选择文件
2.参数{{password}}显示
3.前置脚本,把获取的脚本数据设置成环境变量,传给{{password}},达到参数化
例子2,运行https://www.getpostman.com/collections/cb0cea0af1467c8008fb(postman生成的 )中的所有api,并使用env.json作为环境变量和globals.json作为全局变量,并使用外部data.csv作为外部数据,最后设置了接口请求超时时间为5S
newman run https://www.getpostman.com/collections/cb0cea0af1467c8008fb --environment env.json --iteration-data data.csv --globals globals.json --timeout-request 5000
导出环境变量
导出全局变量:
postman传json数据