当前位置:网站首页>Postman tutorial - scripting
Postman tutorial - scripting
2022-07-07 10:06:00 【Splendid Qianyang 813】
Catalog
1. If it is body The return is html, Want to put html Set the value of to the environment variable ;
2. If body The return is json, You want to set the returned value as an environment variable ;
3. If you want to token Set the value of to the environment variable ;
4. If you want to params Set the value of to the environment variable :
5. If you want to responseBody Medium headers Set the value of to the environment variable ;
6. If you want to put the body Medium text、html、XML、json、JS Set to environment variable ;
7. If you want to responseBody Medium text、XML、json、JS Set to environment variable ;
8. take xml Format response convert to son Format
10. Clear an environment variable
12. take xml Format response convert to son Format
13.response Equal to the expected content
14.json analysis key Check the value of
15. Check response Of header Whether the information has the tested field
18. Set the environment variable
1. If it is body The return is html, Want to put html Set the value of to the environment variable ;
const $ = cheerio.load(responseBody);
pm.environment.set("yuyuedanbianhao", $('span').text());
2. If body The return is json, You want to set the returned value as an environment variable ;
var jsonData =JSON.parse(responseBody);// obtain body All parameters returned in
postman.setEnvironmentVariable("orderid-value",jsonData.result.orderId)
3. If you want to token Set the value of to the environment variable ;
var jsonData =JSON.parse(responseBody);// obtain body All parameters returned in
postman.setEnvironmentVariable("token",jsonData.result.token)
4. If you want to params Set the value of to the environment variable :
5. If you want to responseBody Medium headers Set the value of to the environment variable ;
var data =postman.getResponseHeaders("token");
postman.setEnvironmentVariable("token",data)
6. If you want to put the body Medium text、html、XML、json、JS Set to environment variable ;
7. If you want to responseBody Medium text、XML、json、JS Set to environment variable ;
8. take xml Format response convert to son Format
Response body:Convert XML body to a JSON Object
The corresponding script :
var jsonObject = xml2Json(responseBody);
Parameters :( By default, no parameters need to be set , For interface response) transformable xml
9. Clear a global variable
Clear a global variable
The corresponding script :
postman.clearGlobalVariable("variable_key");
Parameters : Of variables to be cleared key
10. Clear an environment variable
Clear an environment variable
The corresponding script :
postman.clearEnvironmentVariable("variable_key");
Parameters : Of environment variables to be cleared key
11.response Include content
Response body:Contains string
The corresponding script :
tests["Body matches string"] =responseBody.has("string_you_want_to_search");
Parameters : Expected content
12. take xml Format response convert to son Format
Response body:Convert XML body to a JSON Object
The corresponding script :
var jsonObject = xml2Json(responseBody);
Parameters :( By default, no parameters need to be set , For interface response) transformable xml
13.response Equal to the expected content
Response body:Is equal to a string
The corresponding script :
tests["Body is correct"] = responseBody === "response_body_string";
Parameters : expect response
14.json analysis key Check the value of
Response body:JSON value check
The corresponding script :
tests["Args key contains argument passed as url parameter"] = 'test' in responseJSON.args
Parameters :test Replace the measured value ,args Replace the tested key
15. Check response Of header Whether the information has the tested field
Response headers:Content-Type header check
The corresponding script :
tests["Content-Type is present"] = postman.getResponseHeader("Content-Type");
Parameters : expect header
16. Response time judgment
Response time is less than 200ms
The corresponding script :
tests["Response time is less than 200ms"] = responseTime < 200;
Parameters : response time
17. Set global variables
Set an global variable
The corresponding script :
postman.setGlobalVariable("variable_key", "variable_value");
Parameters : The key value of the global variable
18. Set the environment variable
Set an environment variable
The corresponding script :
postman.setEnvironmentVariable("variable_key", "variable_value");
Parameters : Key value of environment variable
19. Judge status code
Status code:Code is 200
The corresponding script :
tests["Status code is 200"] = responseCode.code != 400;
Parameters : Status code
边栏推荐
- Why does the starting service report an error when installing MySQL? (operating system Windows)
- AI moves from perception to intelligent cognition
- Agile course training
- ES类和对象、原型
- Win10 installation vs2015
- 大佬们,有没有遇到过flink cdc读MySQLbinlog丢数据的情况,每次任务重启就有概率丢数
- Scratch crawler mysql, Django, etc
- HCIP 第一天 笔记整理
- Parameter sniffing (1/2)
- 【ORM框架】
猜你喜欢
CSDN salary increase technology - learn about the use of several common logic controllers of JMeter
小程序实现页面多级来回切换支持滑动和点击操作
【无标题】
官媒关注!国内数字藏品平台百强榜发布,行业加速合规健康发展
Win10 installation vs2015
The Himalaya web version will pop up after each pause. It is recommended to download the client solution
Delete a record in the table in pl/sql by mistake, and the recovery method
Agile course training
Win10安装VS2015
【原创】程序员团队管理的核心是什么?
随机推荐
thinkphp3.2信息泄露
HCIP 第一天 笔记整理
Detailed explanation of diffusion model
CodeForces - 1324D Pair of Topics(二分或双指针)
Write it into the SR table in the way of flinksql. It is found that the data to be deleted has not been deleted. Refer to the document https://do
AI moves from perception to intelligent cognition
20排位赛3
Switching value signal anti shake FB of PLC signal processing series
企业实战|复杂业务关系下的银行业运维指标体系建设
ViewPager2和VIewPager的區別以及ViewPager2實現輪播圖
根据热门面试题分析Android事件分发机制(一)
Become a "founder" and make reading a habit
2020 Zhejiang Provincial Games
Why are social portals rarely provided in real estate o2o applications?
Using keras in tensorflow to build convolutional neural network
phpcms实现PC网站接入微信Native支付
Application of C # XML
Phpcms realizes PC website access to wechat native payment
【无标题】
Software modeling and analysis