[share] API post3.0 is a tool for process testing and reference parameter variables

Time:2020-11-6

This issue explains how to use API post for interface automation testing

Apipost has an environment variable setting for the interface process test. The environment variable setting here can distinguish the test environment from the formal environment very well. You only need to create different environment variables for different URLs of the formal environment and the test environment, and then you can clearly distinguish them by calling them.

The first is to create environment variables

[share] API post3.0 is a tool for process testing and reference parameter variables

Click new environment and enter the environment name. Here you can use the formal environment and test environment to name or project name. We use the name of the test environment, and then write the variable name and initial value. The variable name is defined according to your own hobbies and preferences. The initial value of the variable is usually the URL of the home page of the test or the same URL when you test multiple interfaces Fields such as:http://47.95.15.38:8000/login http://47.95.15.38: 8000 / get / user, whose URL is the same field ashttp://47.95.15.38The initial value of 8000 variable can be filled in ashttp://47.95.15.38:8000

[share] API post3.0 is a tool for process testing and reference parameter variables

After the environment variable is configured, it refers to the environment variable. Apipost references the environment variable by adding the environment variable name in the requested URL, such as {{ceshi)_ url}}/login {{ceshi_ url}}/get/user.

[share] API post3.0 is a tool for process testing and reference parameter variables

[share] API post3.0 is a tool for process testing and reference parameter variables

Here we implement a login and login query process operation

First of all, we will get a token after logging in, but the value of token will change in the request after each login. This is a parameter variable. How to call this variable, apipost uses a pre execution script and a post execution script

After logging in, we can check the token in the response

[share] API post3.0 is a tool for process testing and reference parameter variables

Then click to execute the script, and select to set an environment variable on the right

[share] API post3.0 is a tool for process testing and reference parameter variables

Then write the variable name and locate the position of token in the response text. Apipost will fix the format of the request text response.json.token Or the superior of token. Token such as: apt.variables.set (“token_ a”, response.json.result .token);

This is the token of result in JSON in response, and the token is equal to token ﹣ u a

[share] API post3.0 is a tool for process testing and reference parameter variables

After that, we perform the query operation after login, because we have defined that the token value after login is equal to token_ a. Therefore, the token is directly referenced in the body_ a. The reference format is {{token_ a} In this way, we don’t have to change the token frequently after each login request

[share] API post3.0 is a tool for process testing and reference parameter variables

Then process test, select the interface script that has been written and click Run to test the process

[share] API post3.0 is a tool for process testing and reference parameter variables