美文网首页
postman 断言

postman 断言

作者: 微笑的AK47 | 来源:发表于2019-11-25 14:39 被阅读0次

1.环境变量

(1)设置环境变量:

postman.setEnvironmentVariable("key", "value");

(2)获取环境变量:

postman.getEnvironmentVariable("key");

获取一个环境变量(其值是一个字符串对象)

(3)清楚一个环境变量

postman.clearEnvironmentVariable("key");

2.全局变量

(1)设置全局变量:

postman.setGlobalVariable("key", "value");

(2)获取全局变量:

postman.getGlobalVariable("key");

(3)清楚全局变量:

postman.clearGlobalVariable("key");

3.检查响应中包含string

tests["Body matches string"] = responseBody.has("string_you_want_to_search");

4.转化XML格式的响应成JSON对象

var jsonObject = xml2Json(responseBody);

5.检查response是否等于一个字符串

 tests["Body is correct"] = responseBody === "response_body_string";

6.检查JSON某字段值

var data = JSON.parse(responseBody);

tests["Your test name"] = data.value === 100;

7.检查Content-Type是否包含在header返回(大小写不敏感)

 tests["Content-Type is present"] = postman.getResponseHeader("Content-Type");

//Note: the getResponseHeader() method returns the header value, if it exists.

8.检查Content-Type是否包含在header返回(大小写敏感)

 tests["Content-Type is present"] = responseHeaders.hasOwnProperty("Content-Type");

9.响应时间检查

(1)检查请求耗时时间小于200ms

tests["Response time is less than 200ms"] = responseTime < 200;

(2)响应时间在一个特定的范围内(包括下限和上限)

tests["Response time is acceptable"] = _.inRange(responseTime, 100, 1001);

10.检查Status code为200或者301

tests["Status code is 200"] = responseCode.code === 200 || responseCode.code === 301;

11.检查Code name是否包含字符串:

 tests["Status code name has string"] = responseCode.name.has("Created");

12.检查成功post的请求status code

tests["Successful POST request"] = responseCode.code === 201 || responseCode.code === 202;

13. 将TinyValidator用于JSON数据

var schema = {

"items": {

"type": "boolean"

}

};

var data1 = [true, false];

var data2 = [true, 123];

tests["Valid Data1"] = tv4.validate(data1, schema);

tests["Valid Data2"] = tv4.validate(data2, schema);

console.log("Validation failed: ", tv4.error);

————————————————

版权声明:本文为CSDN博主「哈哈哒矮油喂」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/yijinaqingan/article/details/88628071

相关文章

  • 接口测试02-Postman的使用

    Postman 断言 postman 断言借助js 语言编写代码,自动判断预期结果与实际结果是否一致。 断言 代码...

  • postman使用心得(二):postman接口测试断言

    在使用postman做接口测试的时候,可以在tests中对该接口进行断言设置 上面的图为使用postman断言方法...

  • postman 断言

    【Tests】例子 在发送请求并从服务器收到响应后运行测试脚本。 让我们看一下Postman-Tests模块的一些...

  • Postman断言

    一般来说执行完测试,我们需要对测试结果进行校验,判断结果是否符合我们的预期,也就是断言。实例断言内容 响应状态码:...

  • postman 断言

    1.环境变量 (1)设置环境变量: postman.setEnvironmentVariable("key", "...

  • postman 断言

    1.什么是断言 判断程序执行结果是否符合我们的预期就是断言 2.接口测试根据什么判定断言 一般根据程序返回状态码和...

  • Postman 断言

    Postman断言填写在Tests中,通过JavaScript(JS)来实现的。所以要有一点JS的基础。响应断言结...

  • postman断言

    可以使用右边的样例,点击即可使用

  • postman断言记录

    postman 断言: 断言请求结果状态码:status code: Code is 200pm.test("St...

  • 如何使用Fiddler做接口测试?测试小白进阶大咖的必经之路!

    我们都知道使用Postman做接口测试,相比Postman,Fiddler不能写断言,只能构造HTTP请求,并人工...

网友评论

      本文标题:postman 断言

      本文链接:https://www.haomeiwen.com/subject/pbtjwctx.html