Authentication for Rest API
One very important aspect of test case design is repeatable authentication
. In many scenarios, some test steps rely on authentication
, that is, the user needs to log in before performing certain steps. We may encounter the problem that the login step is not repeatable, possible reasons include dynamic input of verification codes during login, or the need for mobile phone verification. Refer to Verification Codes, Verification SMS, and Other Verification Steps.
If your program is designed with a restful api
architecture and the token is stored in local storage such as the browser's cookie, you can operate by manipulating the data storage operation type to write the token into the storage.
Step Instructions
- Open the login page (this step is to enable the browser to access a certain domain name in order to set the browser storage, such as cookies, etc.)
- Generate a long-term token for backup.
- Add a data storage step, and this step writes the above token into the corresponding storage of the browser as needed.
- Open the page to be tested and continue with other steps.
Example Explanation
As shown in the figure below, we have created the following steps:

Open the Login Page
Prepare for writing to the data storage.
Store the Token
As shown in the figure below, store the token in the browser as needed. Here, it is stored in localStorage
.

Open the Console
After opening the console, the corresponding program will read and carry the token, request the rest api, and complete the subsequent steps.