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接口测试_添加断言的更多相关文章

  1. postman(三):添加断言

    进行接口测试时,添加断言时必不可少的,断言就是判断响应内容与预期返回是否一致 进行接口测试时,添加断言时必不可少的,断言就是判断响应内容与预期返回是否一致   postman可以在请求模块的Tests ...

  2. Postman接口测试_基本功能

    一.   安装与更新 1.安装的方式 方式1:chrome插件版本:chrome--->设置--->扩展程序: 方式2:native版本(具有更好的扩展性,推荐使用):https://ww ...

  3. 接口测试工具postman(三)添加断言

    每个用例执行完成后,可以通过添加断言来判断返回结果是否正确,即表示用例执行是否成功. 官方说明文档:https://learning.getpostman.com/docs/postman/scrip ...

  4. #postman接口测试系列:基本操作总结

    最近项目需要接口测试,所以选择了不少工具对比,最终决定使用postman进行接口测试,这个工具目前使用比较简单,但是有点还是比较多的,如下: 方便切换不同的环境进行接口测试工作,而不用修改变量或代码 ...

  5. postman接口测试工具的常规使用

    目录 postman接口测试工具简介与安装 postman发送get请求 JSON数据详解 postman发送post请求 postman中post请求传参说明 postman设置请求的header ...

  6. 【技术博客】Postman接口测试教程 - 环境、附加验证、文件上传测试

    Postman接口测试教程 - 环境.附加验证.文件上传测试 v1.0 作者:ZBW 前言 继利用Postman和Jmeter进行接口性能测试之后,我们发现Postman作为一款入门容易的工具,其内置 ...

  7. postman(九):postman接口测试脚本集成到jenkins

    本篇的目的是实现使用jenkins远程执行postman接口测试脚本 准备工作:一台linux服务器(可以用虚拟机搭建一个),linux服务器上安装好node.js.newman,部署好jenkins ...

  8. Postman 接口测试神器

    Postman 接口测试神器 Postman 是一个接口测试和 http 请求的神器,非常好用. 官方 github 地址: https://github.com/postmanlabs Postma ...

  9. Postman Postman接口测试工具使用简介

    Postman接口测试工具使用简介 by:授客 QQ:1033553122 本文主要是对Postman这个接口测试工具的使用做个简单的介绍,仅供参考. 插件安装 1)下载并安装chrome浏览器 2) ...

随机推荐

  1. SpringMVC Controller中注入Request成员域和在方法中定义中HttpServletRequest有啥区别

    先说结论,在Controller中注入Request是线程安全的. 以下是解释: 我们先来看看这两者有什么不同 在controller注入成员变量request 可以看到注入的是一个代理对象 写在方法 ...

  2. Python 多进程编程之 进程间的通信(在Pool中Queue)

    Python 多进程编程之 进程间的通信(在Pool中Queue) 1,在进程池中进程间的通信,原理与普通进程之间一样,只是引用的方法不同,python对进程池通信有专用的方法 在Manager()中 ...

  3. CSS样式简介

    层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言.CSS不仅可以静态 ...

  4. # 2019-2020-3 《Java 程序设计》第四周总结

    2019-2020-3 <Java 程序设计>第四周知识总结 第五章:继承 1.定义继承关系的语法结构: [修饰符] class 子类名 extends 父类名 { 类体定义 } 父类中应 ...

  5. Webview窗口设置遮罩层

    在Webview窗口中如果存在子Webview的情况下,使用html中的css来做页面遮罩无法覆盖子Webview,为了解决此问题,WebviewStyle对象添加mask属性,用于设置Webview ...

  6. Element.querySelector和Element.querySelectorAll和jQuery(element).find(selector)选择器的区别

    <divid="test1"> <a href="http://www.hujuntao.com/">设计蜂巢</a> &l ...

  7. sass基础常用指南

    一.变量 $global-color:red; .nav{ background:$global-color; } 二.sass命名时横杠和下划线不区分 $global-color:yellow; . ...

  8. python运算符优先级

    下面这个表给出Python的运算符优先级,从最低的优先级(最松散地结合)到最高的优先级(最紧密地结合).这意味着在一个表达式中,Python会首先计算表中较下面的运算符,然后在计算列在表上部的运算符. ...

  9. 背水一战 Windows 10 (81) - 全球化

    [源码下载] 背水一战 Windows 10 (81) - 全球化 作者:webabcd 介绍背水一战 Windows 10 之 全球化 Demo 格式化数字 示例1.演示全球化的基本应用Locali ...

  10. springboot之使用redistemplate优雅地操作redis

    概述 本文内容主要 关于spring-redis 关于redis的key设计 redis的基本数据结构 介绍redis与springboot的整合 sringboot中的redistemplate的使 ...