当前位置:网站首页>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
边栏推荐
- Introduction to energy Router: Architecture and functions for energy Internet
- Agile course training
- Qualifying 3
- How to become a senior digital IC Design Engineer (1-6) Verilog coding Grammar: Classic Digital IC Design
- Application of C # XML
- “十二星座女神降临”全新活动推出
- 反卷积通俗详细解析与nn.ConvTranspose2d重要参数解释
- ORM模型--数据记录的创建操作,查询操作
- Flinkcdc failed to collect Oracle in the snapshot stage. How do you adjust this?
- Why does the starting service report an error when installing MySQL? (operating system Windows)
猜你喜欢

Internship log - day07

Memory ==c language 1

The new activity of "the arrival of twelve constellations and goddesses" was launched
![[original] what is the core of programmer team management?](/img/11/d4b9929e8aadcaee019f656cb3b9fb.png)
[original] what is the core of programmer team management?

PLC信号处理系列之开关量信号防抖FB

Applet sliding, clicking and switching simple UI
![[Frida practice]](/img/20/fc68bcf2f55b140d6754af6364896b.png)
[Frida practice] "one line" code teaches you to obtain all Lua scripts in wegame platform

反卷积通俗详细解析与nn.ConvTranspose2d重要参数解释

web3.0系列之分布式存储IPFS

Natapp intranet penetration
随机推荐
Guys, have you ever encountered the case of losing data when Flink CDC reads mysqlbinlog? Every time the task restarts, there is a probability of losing data
Basic chapter: take you through notes
PostgreSQL创建触发器的时候报错,
How to become a senior digital IC Design Engineer (5-3) theory: ULP low power design technology (Part 2)
【ORM框架】
How to use Mongo shake to realize bidirectional synchronization of mongodb in shake database?
中国首款电音音频类“山野电音”数藏发售来了!
Pytest learning - dayone
PLC信号处理系列之开关量信号防抖FB
Check the example of where the initialization is when C initializes the program
First issue of JS reverse tutorial
arcgis操作:dwg数据转为shp数据
2020 Zhejiang Provincial Games
ViewPager2和VIewPager的區別以及ViewPager2實現輪播圖
C socke server, client, UDP
ORM--逻辑关系与&或;排序操作,更新记录操作,删除记录操作
小程序实现页面多级来回切换支持滑动和点击操作
Introduction to energy Router: Architecture and functions for energy Internet
JS reverse tutorial second issue - Ape anthropology first question
Addition, deletion, modification and query of ThinkPHP database