Postman常用Api

Postman像jmeter一样提供前置处理脚本和后置处理脚本。脚本主要使用JavaScript语法,并内置提供了一些js代码库,提供了一些内置对象和方法。

参考:https://www.getpostman.com/docs/testing_examples

可通过这个链接作为例子进行学习:http://www.getpostman.com/samples/test_data_file.json

  1. 设置环境变量
postman.setEnvironmentVariable("key", "value");
  1. 查询环境变量
postman.getEnvironmentVariable("key");
  1. 设置全局变量
postman.setGlobalVariable("key", "value");
  1. 查询全局变量
postman.getGlobalVariable("key");
  1. 检查Http响应内容是否包含一个字符串
tests["Body matches string"] = responseBody.has("string_you_want_to_search");
  1. 将XML内容转成JSON对象,方便对XML内容进行处理
var jsonObject = xml2Json(responseBody);
  1. 检查Http响应内容是否等于一个字符串
tests["Body is correct"] = responseBody === "response_body_string";
  1. 检查一个JSON值
var data = JSON.parse(responseBody);
tests["Your test name"] = data.value === 100;
  1. 检查一个Http response header是否存在
tests["Content-Type is present"] = postman.getResponseHeader("Content-Type"); //Note: the getResponseHeader() method returns the header value, if it exists.
//这种方式不区分大小写
  1. 检查一个Http response header是否存在(区分大小写)
tests["Content-Type is present"] = responseHeaders.hasOwnProperty("Content-Type");
  1. 对响应时间做断言,如响应时间是否小于200ms
tests["Response time is less than 200ms"] = responseTime < 200;
  1. 对status code进行断言
tests["Status code is 200"] = responseCode.code === 200;
  1. 断言Status messsage是否包含某个字符串
tests["Status code name has string"] = responseCode.name.has("Created");
  1. 断言Status code是否成功
tests["Successful POST request"] = responseCode.code === 200;
  1. 使用TinyValidator框架对
var schema = {
"items": {
"type": "boolean"
}
};
var data1 = [true, false];
var data2 = [true, 123]; tests["Valid Data1"] = tv4.validate(data1, schema);
tests["Valid Data2"] = tv4.validate(data2, schema);
console.log("Validation failed: ", tv4.error);

--

来源我的文章:http://ask.testfan.cn/article/910

Postman编程的更多相关文章

  1. springboot2.0入门(三)----定义编程风格+jackjson使用+postMan测试

    一.RESTFul风格API 1.优点: )看Url就知道要什么资源 )看http method就知道针对资源干什么 )看http status code就知道结果如何 HTTP方法体现对资源的操作: ...

  2. 猫哥网络编程系列:HTTP PEM 万能调试法

    注:本文内容较长且细节较多,建议先收藏再阅读,原文将在 Github 上维护与更新. 在 HTTP 接口开发与调试过程中,我们经常遇到以下类似的问题: 为什么本地环境接口可以调用成功,但放到手机上就跑 ...

  3. 全新 Mac 安装指南(编程篇)(环境变量、Shell 终端、SSH 远程连接)

    注:本文专门用于指导对计算机编程与设计(尤其是互联网产品开发与设计)感兴趣的 Mac 新用户,如何在 Mac OS X 系统上配置开发与上网环境,另有<全新 Mac 安装指南(通用篇)>作 ...

  4. 读《MacTalk&#183;人生元编程》及Mac经常使用软件

    引子 池建强的Blog:http://www.cnblogs.com/chijianqiang/ 用了1年多的黑苹果,是用Windows的思维用UI.用Linux的思维用Shell,折腾的是联想E49 ...

  5. [补] windows C socket编程——大物实验预约

    注 : 心血来潮,想着把这两年没能记录下来的经历,写一波回忆杀.诚然,有些经历十分复杂繁琐,希望能耐下性子,写出好文章来,可惜一时不能全想起来这两年来的种种,就想起来什么便写什么吧. 时间估摸着是大一 ...

  6. 你应该学会的Postman用法

    postman这个神器相信大家都用过,程序员作为非专业的测试人员,非常需要这么一款简单轻量级的restful测试工具,但是不知道你是否知道,postman的强大之处不只是测试一下接口,还有其他非常赞的 ...

  7. 【工具篇】接口测试神器 -- Postman 入门教程

    一.Postman概述 (1)工具介绍 Postman是一个接口测试工具,一款非常流行的API调试工具.在做接口测试的时候,Postman相当于一个客户端,它可以模拟用户发起的各类HTTP请求,将请求 ...

  8. API测试工具SoapUI & Postman对比分析

    本文由葡萄城技术团队于博客园原创并首发 转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 最近公司要引入API测试工具,经过调查和了解,最终决定在SoapUI ...

  9. 看到了必须要Mark啊,最全的编程中英文词汇对照汇总(里面有好几个版本的,每个版本从a到d的顺序排列)

    java:  第一章: JDK(Java Development Kit) java开发工具包 JVM(Java Virtual Machine) java虚拟机 Javac  编译命令 java   ...

随机推荐

  1. Delph组件如何使用自己的图标(转)

    源:http://blog.csdn.net/henreash/article/details/7298451

  2. 【HighCharts系列教程】十、图例属性——legend

    一.legend属性说明 Legend是HighCharts图表的图例属性,如图 默认情况下,HighCharts都会有图例,无特殊情况,默认即可满足需求,所以一般不用配置Legend属性. 二.la ...

  3. Subsequences Summing to Sevens

    Subsequences Summing to Sevens 题目描述 Farmer John's N cows are standing in a row, as they have a tende ...

  4. PAT 天梯赛 L2-005 集合相似度

    set的应用 题目链接 题解 有点像集合的交并操作,直接利用set进行处理,因为set有去重的功能,而且set是利用红黑树实现的,查找速度快O(logN). 代码如下: #include<cst ...

  5. Javascript Fromdata 与jQuery 实现Ajax文件上传

    <!DOCTYPE html> <html> <head> <title>ajax</title> <script type=&quo ...

  6. <Natural Language Processing with Python>学习笔记一

    Spoken input (top left) is analyzed, words are recognized, sentences are parsed and interpreted in c ...

  7. IOS即时通讯XMPP搭建openfire服务器

    一.下载并安装openfire 1.到http://www.igniterealtime.org/downloads/index.jsp下载最新openfire for mac版 比如:Openfir ...

  8. UVa 10945 - Mother bear

    题目大意:给一个字符串,判断是否回文(忽略大小写,忽略非字母字符). #include <cstdio> #include <cctype> #include <cstr ...

  9. Leetcode 176. Second Highest Salary

    Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...

  10. 搭建NDK环境

    2014.07.14 搭建OK,但是目前只能手动编译c代码,具体不清楚.