postman common test scripts

Test script:
Set Environment Variables
var jsonData = JSON.parse(responseBody);
postman.setGlobalVariable("5KMST", jsonData.data.st);
 
(3) .response contains content Response body: Contains string
   Corresponding to the script: 
   tests["Body matches string"] =responseBody.has("string_you_want_to_search");
Parameters: Expected content 
 
(5) .response equal to the expected content Response body: Is equal to a string
   Corresponding to the script: 
   tests["Body is correct"] = responseBody === "response_body_string";
Parameters: Expected response
var jsonData = JSON.parse (responseBody); // request result into JSON format
tests [ "Your test name"] = jsonData.value === 100; // value is a parameter name (based on the interface returns the result to fill), 100 is a value (and the corresponding value) response returned
 
(8). Analyzing the response time Response time is less than 200ms
   Corresponding to the script: 
   tests["Response time is less than 200ms"] = responseTime < 200;
Parameters: response time 
 
(11) determines status code Status code:. Code is 200
     Corresponding to the script: 
     tests["Status code is 200"] = responseCode.code != 400;
     参数:状态码 
 
for语句的用法:

 

 

 

if语句用法:
if(responseCode.code !== 201){
tests["服务器报错"] = true;
}

 

Guess you like

Origin www.cnblogs.com/TomBombadil/p/11005668.html