Symptom: A login interface obtains a token, and the other interfaces need to carry the token when accessing the interface again
Solution:
Step 1: Set the postman environment variable after the login interface is accessed. For example, set the environment variable name: token to the token value in responseBody after the login interface is accessed successfully
Step 2: Read the variable directly when accessing other interfaces. {{variable name}}
Specific steps:
Step 1: Fill in information such as the request body of the login interface
Step 2: Set environment variables
Step 3: Set the source of the environment variable token
Write the following code in Postman Tests to set the environment variables
pm.test("Status code is 200".function() { pm.response.to.have.status(200); }); Var data = json. Parse (responseBody); // Set the environment variable token for the following interface to reference pm.environment.set("token", data.token);
Copy the code
The specific operation is shown as follows:
Step 4: Select an environment and execute it
Step 5: Check whether the token returns the correct value of success
Step 6: Read the variable token value and directly execute other interfaces