Introduction to the PostMan basic fields
Pre-request Script: Execute some Script before PostMan requests it; You can initialize some values for the request as parameters for this request.
Tests: The script to execute after the request is sent successfully.
Tips: Pre-Request Script and Tests currently only support JavaScript.
Dynamic parameter
We use dynamic parameters for the request URL, request body, and so on, using curly braces around the variable (like Vue) : {{variable_name}}
Dynamic URLs:
https://{{xxx}}/user
Dynamic request body
Request Body: Body > raw(JSON)
{"access_token": "{{token}}",}
example
{"side": "{{side}}",}
Before sending the request, we initialize these dynamic variables and write the JS Script in the pre-request Script:
PM. Environment. set('side', switchSide());
Then we will write in the Tests: the actions that need to be done when the request is sent successfully:
pm.test("Status code is 200", () => {pm.response.to.have.status(200); }); / / output variable PM. The test (` side: ${PM. Environment. Get (' side ')}, `, () = > {PM. The response. To. Have. The status (200); });