postman 断言解析
来源:互联网 发布:淘宝毁了dota2 编辑:程序博客网 时间:2024/06/15 16:30
postman 断言解析
最近在学习postman官方文档, 顺势翻译出来,以供学习!
postman断言是JavaScript语言编写的,在postman客户端指定区域编写即可。
断言会在请求返回之后,运行,并根据断言的pass\fail情况体现在最终测试结果中。
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;
13.为JSON data使用微小验证器--Use TinyValidator for JSON data
var schema = {
"items": {
"type": "boolean"
}
};
var data1 = [true, false];
var data2 = [true, 123];
console.log(tv4.error);
tests["Valid Data1"] = tv4.validate(data1, schema);
tests["Valid Data2"] = tv4.validate(data2, schema);
Sample data files
JSON files are composed of key/value pairs
- postman断言解析
- postman 断言解析
- postman断言
- ASSERT(断言)的用法解析
- Postman
- PostMan
- Postman
- postman
- postman
- Postman
- PostMan
- postman
- postman
- PostMan
- postman
- PostMan
- postman
- PostMan
- 开发笔记002
- ReverseFind的用法 ; 查找字符中最后一个字符
- 论文研读--Stacked Attention Networks for Image Question Answering
- linux下mysql5.6搭建MM架构
- HDU 1532 Drainage Ditches (最大流)
- postman 断言解析
- ORA-15041: diskgroup "DATAVG" space exhausted ASM空间假装耗尽不足,resize数据文件和增加数据文件失败
- hdr
- Unicode 和多字节字符集 (MBCS) 支持
- 正则表达式
- web下载七牛云上面的图片资源
- soap协议
- 详解7.0带来的新工具类:DiffUtil
- 模态框的使用