当前位置:网站首页>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
边栏推荐
- Software modeling and analysis
- 【无标题】
- Before joining the chain home, I made a competitive product analysis for myself
- Memory ==c language 1
- 2016 CCPC Hangzhou Onsite
- Why does the starting service report an error when installing MySQL? (operating system Windows)
- HCIP 第一天 笔记整理
- Do you have a boss to help look at this error report and what troubleshooting ideas are there? Oracle CDC 2.2.1 flick 1.14.4
- C# XML的应用
- Write VBA in Excel, connect to Oracle and query the contents in the database
猜你喜欢
[Frida practice] "one line" code teaches you to obtain all Lua scripts in wegame platform
Elaborate on MySQL mvcc multi version control
Basic use of JMeter to proficiency (I) creation and testing of the first task thread from installation
企业实战|复杂业务关系下的银行业运维指标体系建设
【原创】程序员团队管理的核心是什么?
Applet popup half angle mask layer
“十二星座女神降临”全新活动推出
Introduction to energy Router: Architecture and functions for energy Internet
小程序实现页面多级来回切换支持滑动和点击操作
CSDN salary increase technology - learn about the use of several common logic controllers of JMeter
随机推荐
Horizontal split of database
用flinksql的方式 写进 sr的表,发现需要删除的数据没有删除,参照文档https://do
洛谷P2482 [SDOI2010]猪国杀
大佬们,有没有遇到过flink cdc读MySQLbinlog丢数据的情况,每次任务重启就有概率丢数
AI moves from perception to intelligent cognition
EXT2 file system
Using keras in tensorflow to build convolutional neural network
Gauss elimination
使用BigDecimal的坑
Codeforces - 1324d pair of topics
How will fashion brands enter the meta universe?
The new activity of "the arrival of twelve constellations and goddesses" was launched
flinkcdc采集oracle在snapshot阶段一直失败,这个得怎么调整啊?
Flinkcdc failed to collect Oracle in the snapshot stage. How do you adjust this?
Win10 installation vs2015
ORM--查询类型,关联查询
Future development blueprint of agriculture and animal husbandry -- vertical agriculture + artificial meat
Scratch crawler mysql, Django, etc
Deep understanding of UDP, TCP
arcgis操作:dwg数据转为shp数据