Postman—添加断言和检查点

1、打开百度新闻的一个简单的Get请求。点击Send,查看响应信息。百度新闻get请求2、找一个明显的地方 设置检查点及断言
这行吧—【百度新闻——海量中文资讯平台】
设置检查点及断言响应成功点击Url下方的Tests,这里设置检查点及断言。
点进来后这里是空的,你如果熟悉JavaScript的函数,可以直接手动输入,如果不熟悉,postman在右侧已经提供了tests片段。
点击2, 在Tests框内出现一段代码片段,‘“Status code is 200” 意思是生成断言httpCode为200的代码片段。
点击3, 在Tests框内出现一段代码片段,其他不用管,只需要将string_you_want_to_search字符串,替换为:百度新闻——海量中文资讯平台,即可。
然后点击Send发送请求,查看响应信息 ,响应中查看Tests Results。设置的检查全部成功

3、看下失败的
失败失败二、断言内容详解
1.设置环境变量–Setting an environment variable
postman.setEnvironmentVariable(“key”, “value”);

2.设置全局变量–Set a global variable
postman.setGlobalVariable(“key”, “value”);

3.检查响应中包含string–Check if response body contains a string
tests[“Body matches string”] =responseBody.has(“string_you_want_to_search”);

4.转化XML格式的响应成JSON对象—Convert XML body to a JSON object var jsonObject = xml2Json(responseBody);

5.检查响应body中等于指定string–Check if response body is equal to a string
tests[“Body is correct”] = responseBody ===“response_body_string”;

6.检查JSON某字段值–Check for a JSON value
var data = JSON.parse(responseBody);
tests[“Your test name”] = data.value === 100;

7.检查Content-Type是否包含在header返回(大小写不敏感)–Content-Type is present (Case-insensitive checking)
tests[“Content-Type is present”] =postman.getResponseHeader(“Content-Type”); //Note: the getResponseHeader() method returns the header value, if it exists.

8.检查Content-Type是否包含在header返回(大小写敏感)–Content-Type is present (Case-sensitive)
tests[“Content-Type is present”] =responseHeaders.hasOwnProperty(“Content-Type”);

9.检查请求耗时时间小于200ms–Response time is less than 200ms
tests[“Response time is less than 200ms”] = responseTime < 200;

10.检查Status code为200–Status code is 200
tests[“Status code is 200”] = responseCode.code === 200;

11.检查Code name是否指定string–Code name contains a string
tests[“Status code name has string”] =responseCode.name.has(“Created”);

12.检查成功post的请求status code–Succesful POST request status code
tests[“Successful POST request”] = responseCode.code === 201 || responseCode.code === 202;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值