前提:

在chrome网上应用商店安装postman 和 Postman Interceptor.

如下图:

使用postman的时候,最后开启postman Interceptor,如下图:

然后启动,postman工具,开始使用。

其中{{url}}的使用,是因为在设置了环境变量,如下图:

使用{{address}}是因为设置了全局变量,如下图:

Testing 实例

来看一些Postman用于test的例子。这些例子中的大多数在Postman中是有效的,他们像一行JavaScript语句一样简答。在你的request中你可以有很多的test。

注意:test脚本在从服务器收到response后执行

1.设置环境变量:

postman.setEnvironmentVariable("key", "value");

2.设置全局变量:

 postman.setGlobalVariable("key", "value");

3.检查response的body中是否包含字符串:

tests["Body matches string"] = responseBody.has("string_you_want_to_search");

4.把XML的body转换成JSON对象:

var jsonObject = xml2Json(responseBody);

5.检查response的body是都为一个字符串:

tests["Body is correct"] = responseBody === "response_body_string";

6.检查JSON的值:

var data = JSON.parse(responseBody);
tests["Your test name"] = data.value === 100;

7.内容类型存在(检查不区分大小写)

tests["Content-Type is present"] = postman.getResponseHeader("Content-Type"); //Note: the getResponseHeader() method returns the header value, if it exists.

8.内容类型存在(区分大小写):

tests["Content-Type is present"] = responseHeaders.hasOwnProperty("Content-Type");

9.response的响应时间小于200ms:

tests["Response time is less than 200ms"] = responseTime < 200;

10.状态码为200:

tests["Status code is 200"] = responseCode.code === 200;

11.Code name contains a string:

tests["Status code name has string"] = responseCode.name.has("Created");

12.成功的POST request状态码:

tests["Successful POST request"] = responseCode.code === 201 || responseCode.code === 202;

使用postman 测试restful接口的更多相关文章

  1. jmeter 测试restful接口

    jmeter 测试restful接口,JSON数据格式 1.添加线程组 2.添加HTTP信息头管理器 请求发送JSON数据格式参数,需要设置Content-Type为application/json ...

  2. 使用PostMan测试WebService接口

    使用PostMan测试WebService接口 参考资料: 通过XML请求WebServer  https://blog.csdn.net/qq_33933408/article/details/53 ...

  3. 使用Postman对Restful接口进行测试

    趁着项目需要,花了两天时间对postman进行了一下学习,因为看到各大测试群,各个初入测试的孩子们都在问postman,但其实网上也有很多的教程,这里我就再来发一篇. 1. Http协议 要对接口进行 ...

  4. 使用Postman测试https接口时的小问题记录

    测试本地的WebApi接口时,接口是https,自己写的用httpclient测试是可以的, 用postman一直连接不了.原因正是由于https,不过postman在界面上已经给出了可能的原因和解决 ...

  5. postman测试REST接口注意事项

    postman在测试第三方REST接口,当POST请求内容要求为application/json时,注意要在postman中设置POST请求体类型设置为raw,然后设置其内容为application/ ...

  6. Postman测试http接口

    一.安装 官网:https://www.getpostman.com/ Postman是一个Chrome的一个插件工具,我们可以通过Chrome的应用商店进行进行搜索并安装,安装完成会在桌面上显示一个 ...

  7. PostMan测试REST接口时候,如何绕过登录的验证

    原文地址:https://blog.csdn.net/qq_34178998/article/details/80361315 之前测试的时候,需要页面进行登录之后,才能让访问后台程序,但是在进行接口 ...

  8. postMan测试https接口

    一.如何安装postman? Postman下载地址https://www.getpostman.com/ 我下载的版本是Postman-win64-5.0.0-Setup.exe 这是免安装的,可以 ...

  9. postMan测试Controller接口

    1.介绍 Postman是一款功能强大的网页调试与发送网页HTTP请求的Chrome插件. 2.安装 Postman 4.1.2 下载地址: http://files.cnblogs.com/file ...

随机推荐

  1. oc09--NSString

    // // main.m // 类方法,不可以直接访问对象的属性和方法,类方法中可以直接调用类方法. // NSString基本使用 #import <Foundation/Foundation ...

  2. lightoj--1005--Rooks(组合数)

    Rooks Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu Submit Status De ...

  3. 【CQOI 2009】 余数之和

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1257 [算法] k mod i = k - [k / i] * i 所以 (k mo ...

  4. 【POJ 2417】 Discrete Logging

    [题目链接] http://poj.org/problem?id=2417 [算法] Baby-Step,Giant-Step算法 [代码] #include <algorithm> #i ...

  5. Java-Maven:Maven清单

    ylbtech-Java-Maven:Maven清单 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http ...

  6. docker(二):CentOS安装docker

    前置条件 1. CentOS 7:要求系统为64位.系统内核版本为 3.10 以上 使用如下命令,查看机器配置 lsb_release -a uname -a 2. 关闭防火墙 systemctl s ...

  7. 11g Rac PSU20180116手动补丁升级步骤

    手动升级:软件包解压在新建的/home/grid/update 目录下ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1GRID_HOME=/u01 ...

  8. Hashmap 详解和迭代器问题

    重点介绍HashMap.首先介绍一下什么是Map.在数组中我们是通过数组下标来对其内容索引的,而在Map中我们通过对象来对对象进行索引,用来索引的对象叫做key,其对应的对象叫做value.在下文中会 ...

  9. 测试数据准备中用到到csv写文件知识点

    对于大数据测试中,有时需要自己去准备一些数据,用csvreader来写一个比较大的文件就比较方便,下面我就直接贴示例代码了: package com.acxm.amysu.test;import co ...

  10. 关于安卓调用wcf的一些问题

    最近公司有个项目需要和别的系统做对接,对方开放的是webservice接口,搞了很久终于搞出来了,在此记录一下 获取数据的service public class SoapService implem ...