PostMan系列之—-01 简介

1.简介

Postman是一种网页调试与发送网页http请求的chrome插件。我们可以用来很方便的模拟get或者post或者其他方式的请求来调试接口。

2.界面说明


postman有helpers可以帮助我们快速上手一些复杂功能。
1)   Authorization:身份验证,主要用来填写用户名密码,以及一些验签字段。helpers可以解决authentication protocols问题;
2)   Headers:请求的头部信息
3)   Body:post请求时必须要带的参数,里面放一些key-value键值对
4)   Pre-requerst Script:运行在请求之前,语法使用JavaScript语句。可用于在请求之前自定义请求数据。
5)   tests:官网说明 tests标签功能强大,通常用来写测试,它运行在请求之后。支持JavaScript语法。postman每次执行request的时候,会执行tests。测试结果会在tests的tab上面显示一个通过的数量以及对错情况。```

tests高级操作--引用用例csv文档中的预期结果进行断言。
var jsonData = JSON.parse(responseBody) ;
# data.expected 为csv数据文件中的预期结
tests["测试结果通过"] = jsonData.expires_in===data.expected ;

postman还内置了一些重用的js库,基本能满足所有的使用场景,我们常用内置的函数包括:

Lodash:一个基础的函数库
JS utility library

jQuery (Deprecated):
Cross-platform JavaScript library. This will be removed in future versions of the sandbox.

BackboneJS (Deprecated):js的mvc框架
Provides simple models, views, and collections. This will be removed in future versions of the sandbox.

SugarJS:
Extends native JS objects with useful methods

tv4 JSON schema validator:
Validates JSON objects against v4 of the json-schema draft

CryptoJS:js加密库,支持几乎所有的常用加密方式
standard and secure cryptographic algorithms. Supported algorithms: AES, DES, EvpKDF, HMAC-MD5, HMAC-SHA1/3/256/512, MD5, PBKDF2, Rabbit, SHA1/3/224/256/512, TripleDES

xml2Json(xmlString):
This function behaves the same in Newman and Postman

xmlToJson(xmlString)(Deprecated):
This function does NOT behave the same in Newman and Postman

postman.getResponseHeader(headerName) (Test-only):
returns the response header with name "headerName", if it exists. Returns null if no such header exists. Note: According to W3C specifications, header names are case-insensitive. This method takes care of this.
postman.getResponseHeader("Content-type") and postman.getResponseHeader("content-Type") will return the same value.

3.参数化

1)   全局变量参数化
在环境变量里面设置参数,一套测试用例环境不同可设置多套环境变量。
引用变量用法:{{变量名}}

2)   批量请求参数化:
比如请求接口URL 是一样的,需要创建 50 个 request,创建一个就好,变量参数化即可。如变量为ID

2.1)   将所有的 ID 存储到 txt 或 csv 文档中,以备参数化使用。第一行是参数名,其他行为参数。在环境变量里面设置一个变量 secid,如下图

2.2)   在Pre-request Script(请求运行前会运行该脚本) 里面获取 ID 并设置到环境变量里面:

var secids = data.secids;
pm.environment.set("secid", secids);

2.3)   点击 Run 之后,在 Collection Runner 里面进行导入 data.txt,并获取参数

4.Postman请求Https接口

  1. File->Setting->General,关闭“SSL certificate verification”

  2. 在上面的弹出界面中选择Certificates,并点击 添加证书

CRT file为客户端密钥库的公钥
KEY file为客户端密钥库的私钥
Passphrase为密钥库的密码,

猜你喜欢

转载自www.cnblogs.com/liuyitan/p/12877960.html