最近在学习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 断言解析的更多相关文章

  1. postman断言作用及怎么使用

    这段时间一直在学习postman,在请求中使用断言,很多人不是很了解postman断言,其实呢,postman断言是JavaScript语言编写的,在postman客户端指定区域编写即可. 1.设置环 ...

  2. postman断言分析

    最近测试中用到postman,使用后就简单总结下常用的断言,下面带图的自己最常用的,其他的没怎么用. postman断言是JavaScript语言编写的,在postman客户端指定区域编写即可. 断言 ...

  3. postman断言

    较旧的写作邮差测试风格 较旧的Postman测试编写风格依赖于特殊tests对象的设置值.您可以为对象中的元素设置描述性键,然后说明它是真还是假.例如,tests["Body contain ...

  4. postman 断言学习

    请求 url :https://www.v2ex.com/api/nodes/show.json?name=python get请求 postman发起请求并做断言 断言: tests["B ...

  5. 二、postman断言及正则表达式取值

    postman老式断言与新式断言总结:本文以微信开发者文档为例 断言处如图所示 一.老式断言 老式断言总结:var variables相当于代码中定义的变量,test['']=true;相当于pyth ...

  6. Go的类型断言解析

    经常地我们对一个接口值的动态类型是不确定的,如方法的形参为接口类型时,此时就需要检验它是否符合我们需要的类型.类型断言是一个使用在接口值上的操作.断言类型的语法:x.(T),这里x表示一个接口的类型, ...

  7. postman 断言

    //断言 pm.test("message等于'操作成功'", function () { var jsonData = pm.response.json(); console.l ...

  8. postman断言的方法

    1.在test添加断言 2.检查response的body中是否包含字符串: tests["Body matches string"] = responseBody.has(&qu ...

  9. postman断言的几种方式(二)

    1.检查响应体是否包含字符串 pm.test("Body matches string", function () { pm.expect(pm.response.text()). ...

随机推荐

  1. PHPSTORM设置新建PHP文件头部注释

    1.选择 File|setting 2.在Editor|File and Code Templates,见下图标记更改即可

  2. Windows Server 2012 在桌面上显示”我的电脑”图标

    1.本地方式如果是在Windows Server 2012本地控制台下,直接按Win(键盘上的微软徽标键)+R,输入: rundll32.exe shell32.dll,Control_RunDLL ...

  3. yii小细节

    1.main.php增加导航栏严格区分大小写,否则会出现404错误 2.增加'分页'功能---前后台的models里面的search.php 添加 public function search($pa ...

  4. jQuery checkbox的全选与反选

    1:checkbox的全选与反选 js 代码 $("#cbAll").click(function(){ if($("#cbAll").is(":ch ...

  5. 编译器--__attribute__ ((packed))

    1. __attribute__ ((packed)) 的作用就是告诉编译器取消结构在编译过程中的优化对齐,按照实际占用字节数进行对齐,是GCC特有的语法.这个功能是跟操作系统没关系,跟编译器有关,g ...

  6. GroupBy(..)的四种声明方式的理解及调用

    这里我们以 List<Student> studs作为 source,但是注意,studs中的学生可以是分别属于不同的班级和年级 先看GroupBy的第一种声明: public stati ...

  7. CSS 中Font Awesome 图标(附码表)

    HTML中缩放的矢量图标,您可以使用CSS所提供的所有特性对它们进行更改,包括:大小.颜色.阴影或者其它任何支持的效果. Font Awesome 传送门:http://fontawesome.das ...

  8. iOS打包ipa给客户测试流程

    IOS项目开发的过程中经常会用到一个测试的问题,特别是外包的项目,客户拿了那么多钱,看不到产品时时的进度说不过去,而且UI和功能是否和符合用户需求这个很重要,需要客户的认同. 所以就需要时时给开发中的 ...

  9. DBCP连接池

    方法一: package DBCPUtils; import java.util.List;import java.util.Properties; import javax.sql.DataSour ...

  10. teamviewer "TeamViewer Daemon is not running

    执行下面的命令问题解决: # teamviewer --daemon enable enable Sat Jan :: CST Action: Installing daemon () for 'up ...