当前位置:网站首页>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
边栏推荐
- ORM--数据库增删改查操作逻辑
- How will fashion brands enter the meta universe?
- First issue of JS reverse tutorial
- How to use Mongo shake to realize bidirectional synchronization of mongodb in shake database?
- C# XML的应用
- Natapp intranet penetration
- 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
- Diffusion模型详解
- CDZSC_2022寒假个人训练赛21级(2)
- Basic chapter: take you through notes
猜你喜欢
官媒关注!国内数字藏品平台百强榜发布,行业加速合规健康发展
能源路由器入门必读:面向能源互联网的架构和功能
Delete a record in the table in pl/sql by mistake, and the recovery method
Elaborate on MySQL mvcc multi version control
ORM模型--数据记录的创建操作,查询操作
Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
农牧业未来发展蓝图--垂直农业+人造肉
Google Colab装载Google Drive(Google Colab中使用Google Drive)
web3.0系列之分布式存储IPFS
使用BigDecimal的坑
随机推荐
PostgreSQL创建触发器的时候报错,
ORM模型--数据记录的创建操作,查询操作
ORM--逻辑关系与&或;排序操作,更新记录操作,删除记录操作
[untitled]
终于可以一行代码也不用改了!ShardingSphere 原生驱动问世
How to use Mongo shake to realize bidirectional synchronization of mongodb in shake database?
Future development blueprint of agriculture and animal husbandry -- vertical agriculture + artificial meat
Elaborate on MySQL mvcc multi version control
Internship log - day04
基础篇:带你从头到尾玩转注解
CDZSC_ 2022 winter vacation personal training match level 21 (2)
Can't connect to MySQL server on '(10060) solution summary
Arthas simple instructions
剑指 Offer II 107. 矩阵中的距离
小程序滑动、点击切换简洁UI
【frida实战】“一行”代码教你获取WeGame平台中所有的lua脚本
Parameter sniffing (1/2)
Qualifying 3
Gym - 102219j kitchen plates (violent or topological sequence)
Applet sliding, clicking and switching simple UI