Postman interface automatic dynamic value transfer parameter

The variables of the interface are sometimes not known from the beginning, but are obtained from the result of the previous interface running. Therefore, the above data value and the following data parameter transmission are also a key to interface automation.

 

The most common is to log in to obtain a token, and to obtain a timestamp in advance, which is widely used in many places.

Pre-fetch timestamps (in milliseconds here) in pre_request script

postman.setEnvironmentVariable("timestamp", Math.round(new Date().getTime()/1000));

Add the obtained timestamp variable to the request header information (the specific variable name is mainly based on the interface document)

 

 

send request

 

The token in the returned result is the necessary header information that is commonly used for subsequent various session requests, but this is dynamic, so it must be dynamically obtained.

var jsonData = JSON.parse(responseBody);//Escape the returned message to json format and store it in the variable jsonData

postman.setEnvironmentVariable("UserID",jsonData.UserID);//Set the environment variable UserID, the value is the UserID field in
jsonData postman.setEnvironmentVariable("Token",jsonData.Token);//Set the environment variable Token, the value for the Token field in jsonData

 

After obtaining, you can check whether the variable is obtained in the environment variable. For the use of the variable, please refer to the previous section http://www.cnblogs.com/teresa135/p/9009696.html

 

At this point, the postman interface test automation dynamic value parameter transfer is over, and the summary is as follows:

1- Get the variable value from the pre-request script;

2- The header or body passes in the obtained variable to request;

3-Escape the return message in tests and intercept the fields and store them in variables;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326104491&siteId=291194637