newman执行postman集合

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数据

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值