Postman接口测试_添加断言
1.设置环境变量
postman.setEnvironmentVariable("key", "value");
例子: postman.setEnvironmentVariable("url", "http://192.168.36.47/v2/api");
使用环境变量的格式:{{url}}
1.1清除环境变量
postman.clearEnvironmentVariable("variable_key");
例子:postman.clearEnvironmentVariable("url");
2.设置一个全局变量
postman.setGlobalVariable("key", "value");
例子:postman.setGlobalVariable("username", "123@qq.com");
使用全局变量格式:{{variableName}}
2.1清除一个全局变量
postman.clearGlobalVariable("key", "value");
例子:postman.clearGlobalVariable("username", "123@qq.com");
3.检查响应体包含一个字符串
tests["Body matches string"] = responseBody.has("string_you_want_to_search");
例子:响应体包含以下字段 "path": "field is read-only",
tests["Body matches string"] = responseBody.has("field is read-only");
tests["Body matches string"] = responseBody.has("path");
4.转换XML身体JSON对象
var jsonObject = xml2Json(responseBody);
5.检查响应体等于一个字符串
tests["Body is correct"] = responseBody === "response_body_string";
例子:响应体包含以下字段 "path": "field is read-only",
tests["Body is correct"] = responseBody === "response_body_string";
6.检查一个JSON值
var data = JSON.parse(responseBody);
tests["Your test name"] = data.value === 100;
7.Content-Type的存在(不区分大小写检查)
tests["Content-Type is present"] = postman.getResponseHeader("Content-Type"); //Note: the getResponseHeader() method returns the header value, if it exists.
8.Content-Type的存在(区分大小写)
tests["Content-Type is present"] = responseHeaders.hasOwnProperty("Content-Type");
9.响应时间小于200ms的
tests["Response time is less than 200ms"] = responseTime < 200;
10.状态代码是200
tests["Status code is 200"] = responseCode.code === 200;
例子:状态码是404
tests["Status code is 404"] = responseCode.code === 404;
11.代号包含一个字符串
tests["Status code name has string"] = responseCode.name.has("Created");
例子:Status:201 CREATED
tests["Status code is 201"] = responseCode.code === 201;
tests["Status code name has string"] = responseCode.name.has("Created");
12.成功的POST请求的状态代码
tests["Successful POST request"] = responseCode.code === 201 || responseCode.code === 202;
Postman接口测试_添加断言的更多相关文章
- postman(三):添加断言
进行接口测试时,添加断言时必不可少的,断言就是判断响应内容与预期返回是否一致 进行接口测试时,添加断言时必不可少的,断言就是判断响应内容与预期返回是否一致 postman可以在请求模块的Tests ...
- Postman接口测试_基本功能
一. 安装与更新 1.安装的方式 方式1:chrome插件版本:chrome--->设置--->扩展程序: 方式2:native版本(具有更好的扩展性,推荐使用):https://ww ...
- 接口测试工具postman(三)添加断言
每个用例执行完成后,可以通过添加断言来判断返回结果是否正确,即表示用例执行是否成功. 官方说明文档:https://learning.getpostman.com/docs/postman/scrip ...
- #postman接口测试系列:基本操作总结
最近项目需要接口测试,所以选择了不少工具对比,最终决定使用postman进行接口测试,这个工具目前使用比较简单,但是有点还是比较多的,如下: 方便切换不同的环境进行接口测试工作,而不用修改变量或代码 ...
- postman接口测试工具的常规使用
目录 postman接口测试工具简介与安装 postman发送get请求 JSON数据详解 postman发送post请求 postman中post请求传参说明 postman设置请求的header ...
- 【技术博客】Postman接口测试教程 - 环境、附加验证、文件上传测试
Postman接口测试教程 - 环境.附加验证.文件上传测试 v1.0 作者:ZBW 前言 继利用Postman和Jmeter进行接口性能测试之后,我们发现Postman作为一款入门容易的工具,其内置 ...
- postman(九):postman接口测试脚本集成到jenkins
本篇的目的是实现使用jenkins远程执行postman接口测试脚本 准备工作:一台linux服务器(可以用虚拟机搭建一个),linux服务器上安装好node.js.newman,部署好jenkins ...
- Postman 接口测试神器
Postman 接口测试神器 Postman 是一个接口测试和 http 请求的神器,非常好用. 官方 github 地址: https://github.com/postmanlabs Postma ...
- Postman Postman接口测试工具使用简介
Postman接口测试工具使用简介 by:授客 QQ:1033553122 本文主要是对Postman这个接口测试工具的使用做个简单的介绍,仅供参考. 插件安装 1)下载并安装chrome浏览器 2) ...
随机推荐
- docker-compose安装redis-sentinel集群(1主+2副+2哨兵)
前提:本试验环境已经提前安装了docker和docker-compose 说明:本次部署是单机伪集群,想要部署真正的集群,需要将秒个主件拆分到各个机器上去部署,只修改ip地址 1.下载redis的相关 ...
- Redis Sentinel 模拟故障迁移
什么是redis sentinel 参考文档:https://redis.io/topics/sentinel 简单的来说,就是Redis Sentinel 为redis 提供高可用性,主要体现在下面 ...
- 网页中的数据的4个处理方式:CRUD(Creat, Retrive, Update, Delete)
网页中的数据的4个处理方式:CRUD(Creat, Retrive, Update, Delete) 2018-12-21, 后续完善
- Linux合上笔记本不进入休眠模式
最近一个问题困扰了我很久,入职之前和人事说过工作中会用自己的电脑,但是人事还是坚持要给我发一个电脑,没办法,公司没有补贴,那就领了吧,索性将这个笔记本配置成了Fedora系统,用来当测试机,但是一 ...
- CPU性能分析
CPU性能分析工具 lscpu:查看CPU硬件信息 lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Litt ...
- 2018/7/26号碰到了个奇怪的问题(http有问题,但是ftp没毛病)
过程大概是这样的 本来测试服务器中发ajax没问题,突然暴毙了,服务器又通过ajax发了另外一个请求(与之前不一样). nginx reload 没毛病 ,ftp 也使用正常. 出了什么问题呢? ...
- String的substring方法
string.substring(beginIndex, endIndex) 左闭右开. 测试 public static void main(String[] args) { String a = ...
- spring框架学习笔记6:JDBC模板
JDBC模板:Spring中对数据库的操作. 这一部分对熟悉DBUtils的QueryRunner的开发者来说,非常简单 这是以前我简单写的dbutils的知识: http://www.cnblogs ...
- Java学习笔记41(Properties类)
Properties可以做到集合的数据持久存储 它是map接口的一个实现类,可以使用map类的方法, 不过存在区别:它没有泛型,规定键类型为字符串 这个集合在以后的开发中会经常用到,比如连接数据库等 ...
- [CocoaPods]使用Trunk进行设置
CocoaPods Trunk CocoaPods Trunk是一种身份验证和CocoaPods API服务.要将新的或更新的库发布到CocoaPods以进行公开发布,您需要在Trunk中注册并在当前 ...