五、postman-sandbox

一、在postman中运行一些JavaScript代码的地方

  • 公共库(javascript)
  • 环境变量与全局变量
  • 动态变量
  • 操作cookie
  • 获取和查看请求及响应
  • 读取数据文件

二、api文档

https://www.getpostman.com/docs/postman/scripts/postman_sandbox_api_reference

pm.test('environment to be production',function(){
    pm.expect(pm.environment.get( 'env' )).to.equal( 'production' );
});
pm.test("response should be okay to process",function(){
    pm.response.to.not.be.error;
    pm.response.to.have.jsonBody('');
    pm.response.to.not.have.jsonBody( 'error' );
});

实例操作

tests["状态码必须是200"] = responseCode.code ===200;

var res= JSON.parse(responseBody);

console.log(res.length);

tests["必须返回10条数据"] = res.length ===10;

pm.test('返回正确的状态码', function (){
    pm.expect(pm.response).to.have.status(200);
    pm.expect(pm.response).to.be.success;
});

猜你喜欢

转载自www.cnblogs.com/xinxin1994/p/11258711.html
今日推荐