最近在学习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. fastcgi与cgi的区别

    fastcgi与cgi的区别 先讲下cgi:cgi在2000年或更早的时候用得比较多, 以前web服务器一般只处理静态的请求,如果碰到一个动态请求怎么办呢?web服务器会根据这次请求的内容,然后会fo ...

  2. WinForm各种API---时时更新

    好文要顶 关注我 收藏该文 徐淳 关注 - 1 粉丝 - 3       0 0     本文原文地址:http://www.cnblogs.com/hqxc/p/6160685.html 徐淳 [D ...

  3. Ubuntu14.04安装配置web/ftp/tftp/dns服务器

    目录: 1.安装ftp服务器vsftpd --基于tcp,需要帐号密码 2.安装tftp服务器tftpd-hpa,tftp-hpa --udp 3.web服务器--使用Apache2+Mysql+PH ...

  4. mysql 5.5 修改字符编码

    修改/etc/mysql/my.cnf 配置文件: 最后重启mysql 服务,再查看: 编码已经改好了,可以支持中文字符编码了.

  5. JAVA基础学习——1.0 Java概述

    Java语言 SUN公司  1995年推出的高级编程语言 ■  主要应用方向 Web开发和Android开发 ■  主要特点 平台无关性:能运行于不同的平台上    安全性:去掉了指针操作,内存由操作 ...

  6. 如何设置redis中hash的field的expire ?

    redis > hset expire:me name tom (integer) redis > hget expire:me name "tom" redis &g ...

  7. 伪元素::after和::before

    ::after是一个CSS伪元素,使用::after,你可以从CSS里往页面上新增内容(不再要在HTML里有相应的东西).虽然最终生成的东西并不是真正的DOM里的内容,但这些内容能像普通内容一样显示, ...

  8. asp.net mvc ajax FileUpload

    //后台代码 [HttpPost] public ActionResult CreateCategory(HttpPostedFileBase file) { string url = Upload( ...

  9. 带蒙版的提交loading页面实现

    废话不多说,直接上代码. 首先是HTML中层的实现: <!-- loading 层 --> <div id="loadingDivBack" style=&quo ...

  10. iOS推送小结(证书的生成、客户端的开发、服务端的开发)

    1.推送过程简介 1.1.App启动过程中,使用UIApplication::registerForRemoteNotificationTypes函数与苹果的APNS服务器通信,发出注册远程推送的申请 ...