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,在请求中使用断言,很多人不是很了解postman断言,其实呢,postman断言是JavaScript语言编写的,在postman客户端指定区域编写即可. 1.设置环 ...
- postman断言分析
最近测试中用到postman,使用后就简单总结下常用的断言,下面带图的自己最常用的,其他的没怎么用. postman断言是JavaScript语言编写的,在postman客户端指定区域编写即可. 断言 ...
- postman断言
较旧的写作邮差测试风格 较旧的Postman测试编写风格依赖于特殊tests对象的设置值.您可以为对象中的元素设置描述性键,然后说明它是真还是假.例如,tests["Body contain ...
- postman 断言学习
请求 url :https://www.v2ex.com/api/nodes/show.json?name=python get请求 postman发起请求并做断言 断言: tests["B ...
- 二、postman断言及正则表达式取值
postman老式断言与新式断言总结:本文以微信开发者文档为例 断言处如图所示 一.老式断言 老式断言总结:var variables相当于代码中定义的变量,test['']=true;相当于pyth ...
- Go的类型断言解析
经常地我们对一个接口值的动态类型是不确定的,如方法的形参为接口类型时,此时就需要检验它是否符合我们需要的类型.类型断言是一个使用在接口值上的操作.断言类型的语法:x.(T),这里x表示一个接口的类型, ...
- postman 断言
//断言 pm.test("message等于'操作成功'", function () { var jsonData = pm.response.json(); console.l ...
- postman断言的方法
1.在test添加断言 2.检查response的body中是否包含字符串: tests["Body matches string"] = responseBody.has(&qu ...
- postman断言的几种方式(二)
1.检查响应体是否包含字符串 pm.test("Body matches string", function () { pm.expect(pm.response.text()). ...
随机推荐
- angularJS select
ng-options指令 在angularJS中创建select下拉是使用ng-options创建下拉项 ng-options="val as label for element in ar ...
- (转)实现DataList的分页 新增列
前几天在做网上商城,要展示商品信息(有图片,有文字),DataView虽然可以分页,但它的缺点是不能自定义显示格式.而DataList解决了它的缺点,但DataList本身却不能分页.很是头痛,于是在 ...
- delphi tidhttp 超时设置无效的解决方法
现在delphi都发布到xe8了,tidhttp还有缺陷,那就是超时设置在没有网络或者连不上服务器的时候是无效的,不管你设置为多少都要10-20秒.connectTimeout和readTimeout ...
- Unity3D 计算FPS
using UnityEngine; using System.Collections; public class FPS : MonoBehaviour { private const string ...
- 【翻译】首个基于NHibernate的应用程序
首个基于NHibernate的应用程序 Your first NHibernate based application 英文原文地址:http://www.nhforge.org/wikis/how ...
- PEtools
// PETools.cpp : Defines the entry point for the console application.// #include "stdafx.h" ...
- 【Django】--Models 和ORM以及admin配置
Models 数据库的配置 1 django默认支持sqlite,mysql, oracle,postgresql数据库 <1>sqlite django默认使用sqlite的数据库 ...
- 基于SSM的租赁管理系统0.2_20161225_开发环境
项目环境搭建 1. 开发环境 Sybase PowerDesigner 15.1.0 + MySQL 5.7.15 + Navicat 11.0.9 + eclipse EE Mars 2.0 + F ...
- 21. Merge Two Sorted Lists —— Python
题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splici ...
- iOS推送小结(证书的生成、客户端的开发、服务端的开发)
1.推送过程简介 1.1.App启动过程中,使用UIApplication::registerForRemoteNotificationTypes函数与苹果的APNS服务器通信,发出注册远程推送的申请 ...