使用postman 测试restful接口
前提:
在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接口的更多相关文章
- jmeter 测试restful接口
jmeter 测试restful接口,JSON数据格式 1.添加线程组 2.添加HTTP信息头管理器 请求发送JSON数据格式参数,需要设置Content-Type为application/json ...
- 使用PostMan测试WebService接口
使用PostMan测试WebService接口 参考资料: 通过XML请求WebServer https://blog.csdn.net/qq_33933408/article/details/53 ...
- 使用Postman对Restful接口进行测试
趁着项目需要,花了两天时间对postman进行了一下学习,因为看到各大测试群,各个初入测试的孩子们都在问postman,但其实网上也有很多的教程,这里我就再来发一篇. 1. Http协议 要对接口进行 ...
- 使用Postman测试https接口时的小问题记录
测试本地的WebApi接口时,接口是https,自己写的用httpclient测试是可以的, 用postman一直连接不了.原因正是由于https,不过postman在界面上已经给出了可能的原因和解决 ...
- postman测试REST接口注意事项
postman在测试第三方REST接口,当POST请求内容要求为application/json时,注意要在postman中设置POST请求体类型设置为raw,然后设置其内容为application/ ...
- Postman测试http接口
一.安装 官网:https://www.getpostman.com/ Postman是一个Chrome的一个插件工具,我们可以通过Chrome的应用商店进行进行搜索并安装,安装完成会在桌面上显示一个 ...
- PostMan测试REST接口时候,如何绕过登录的验证
原文地址:https://blog.csdn.net/qq_34178998/article/details/80361315 之前测试的时候,需要页面进行登录之后,才能让访问后台程序,但是在进行接口 ...
- postMan测试https接口
一.如何安装postman? Postman下载地址https://www.getpostman.com/ 我下载的版本是Postman-win64-5.0.0-Setup.exe 这是免安装的,可以 ...
- postMan测试Controller接口
1.介绍 Postman是一款功能强大的网页调试与发送网页HTTP请求的Chrome插件. 2.安装 Postman 4.1.2 下载地址: http://files.cnblogs.com/file ...
随机推荐
- 在Android系统中添加宏控制代码【原创】
关键词:Android 宏控制 Androd.mk 平台信息:内核:linux3.4.39 系统:android/android5.1平台:S5P4418 作者:庄泽彬(欢迎转载,请注明作者) 邮 ...
- js分享代码
<<!DOCTYPE html><html><head> <title></title></head> <body& ...
- MyBatis输出执行的SQL到控制台
src\main\resources\application.properties 或者src\main\resources\application.yml 在你的application.proper ...
- React+webpack
webPack + React 步骤: 1. 创建文件夹 src 源代码目录 main.js 打包的入口文件 App.js 项目的根组件 import React,{Component} from ' ...
- 常用的CSS命名
头:header 内容:content/container 尾:footer 导航:nav 侧栏:sidebar 栏目:column 页面外围控制整体佈局宽度:wrapper 左右中:left rig ...
- Android Drawable之getIntrinsicWidth()和getIntrinsicHeight()
在Android的开发中,凡是需要画图的地方大都离不开类Drawable.Android的官方文档中介绍这个类就是被设计用来表示可以被画的东西.A Drawable is a ge ...
- python爬虫:爬取凤凰指数
在知乎上看到的这个问题,讲讲我爬取过程中遇到的问题: 1.循环爬取其他页面,在其他项目中用循环一般可以搞定,可是这个,第一页和第二第三页的表格是不同的,所以要重新写规则,我懒,写了第一页后,就不想在写 ...
- WAMP安装之坑
Apache安装目录不能有空格 Apache根目录修改后不能直接localhost打开,可以通过改变端口,然后输入 localhost:端口号 打开
- 2017/01/07 学习笔记 jar包,maven
① 关于tar,jar,war文件 tar是通用的另一种打包格式,为了部署到服务器时方便. jar是java app server识别的java部署格式,其实是Zip文件,只是内部的文件有规范. wa ...
- (转) RabbitMQ学习之spring整合发送同步消息(注解实现)
http://blog.csdn.net/zhu_tianwei/article/details/40918477 上一篇文章通过xml配置rabbitmq的rabbitTemplate,本节将使用注 ...