Test login state keeping method, system and equipment and storage medium
By using the browser session storage mechanism to store authentication tokens in UI automation testing, the inefficiency and security risks caused by repeated logins are resolved, achieving efficient and stable login state maintenance, and is applicable to multiple browsers.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GUANGXI XINGWANG ZHIYUN TECH CO LTD
- Filing Date
- 2025-12-17
- Publication Date
- 2026-04-17
AI Technical Summary
In existing UI automation testing, repeatedly executing the login process leads to low testing efficiency, increases testing time, and frequent login requests trigger security policies, affecting test stability, especially since complex verification steps are difficult to automate.
By obtaining a valid authentication token and storing it in the browser's session storage, the browser's native session storage mechanism is utilized, and automated tools inject the token to maintain the login state, avoid repeated login processes, and support scheduled updates and multi-token verification.
It improves testing efficiency by more than 50%, reduces security risks, enhances testing stability, simplifies complex verification processes, is compatible with multiple browsers, and has strong applicability.
Smart Images

Figure CN121880179A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of UI automation testing technology, and more specifically, to a method, system, device, and storage medium for testing login state maintenance. Background Technology
[0002] In UI automation testing, most test scenarios require the user to be logged in. Existing technologies typically maintain the login state by repeatedly executing the login process; that is, each time a test case is executed, a script simulates actions such as entering a username, password, and clicking the login button.
[0003] This approach has several drawbacks: First, repeatedly executing login steps leads to low testing efficiency, especially when there are many test cases, which significantly increases the overall testing time. Second, frequent login requests can easily trigger the target system's security policies, such as IP blocking and temporary account locking, causing test interruptions. Third, automating login processes that involve complex verification steps such as CAPTCHA and SMS verification is difficult, further affecting test stability.
[0004] Therefore, a UI automation testing method is needed that can avoid repeatedly executing the login process and efficiently maintain the login status. Summary of the Invention
[0005] The technical problem to be solved by the present invention is to address the above-mentioned shortcomings of the prior art. The purpose of the present invention is to provide a method for maintaining login status during testing, which can improve testing efficiency and reduce security risks.
[0006] The second objective of this invention is to provide a test login status maintenance system.
[0007] The third objective of this invention is to provide a computer device.
[0008] The fourth objective of this invention is to provide a computer storage medium.
[0009] To achieve the first objective mentioned above, the present invention provides a method for testing login status maintenance, comprising the following steps: Step 1. Obtain a valid authentication token and execute a complete login process. Simulate user login operations using a UI automation testing tool. After successful login, retrieve the valid authentication token from the browser session storage. Step 2. Store the authentication token: Save the extracted authentication token to the test framework's configuration file or variable; Step 3. Set up session storage to maintain login status. Before executing subsequent test cases, use the script execution interface provided by the UI automation testing tool to call the browser's built-in session storage setting method to write the saved authentication token into the current browser session storage. Step 4. Execute the test cases. After completing the session storage settings, directly access the page that requires login permissions. The browser will automatically recognize the authentication token in the session storage and maintain the user's login status without having to execute the login process again. Step 5. Session storage cleanup: After all test cases have been executed, clear the authentication token in the browser session storage to avoid affecting subsequent tests.
[0010] As a further improvement, in step 1, if the authentication token of the target system has an expiration period, a timed detection mechanism is set up so that when the authentication token is about to expire, the login process is automatically re-executed to obtain a new token and update the storage.
[0011] Furthermore, in step 1, the browser's native sessionStorage mechanism is used to write the valid authentication token obtained during the first login directly to the browser's session storage via an automated script, so that subsequent test cases can inherit the login state without having to repeat the login process.
[0012] Furthermore, in step 3, it is possible to set multiple session storage key-value pairs simultaneously to adapt to complex login scenarios that require multi-token authentication.
[0013] Furthermore, in step 3, the browser script is called through the webdriver.Firefox().execute_script() interface to execute the window.sessionStorage.setItem() operation to inject the token, thus combining the browser's native functionality with the automated testing tool.
[0014] To achieve the second objective mentioned above, the present invention provides a system for testing login status maintenance, comprising: The acquisition module is used to obtain a valid authentication token, execute a complete login process, simulate user login operations through UI automation testing tools, and retrieve the valid authentication token from the browser session storage after successful login. The storage module is used to store authentication tokens, saving the extracted authentication tokens to the test framework's configuration file or variables; The settings module is used to configure session storage to maintain login status. Before subsequent test cases are executed, the script execution interface provided by the UI automation testing tool calls the browser's built-in session storage settings method to write the saved authentication token into the current browser session storage. The execution module is used to execute test cases. After completing the session storage settings, you can directly access pages that require login permissions. The browser will automatically recognize the authentication token in the session storage and maintain the user's login status without having to execute the login process again. The cleanup module is used to clean up the session storage. After all test cases have been executed, the authentication token in the browser session storage is cleared to avoid affecting subsequent tests.
[0015] To achieve the third objective mentioned above, the present invention provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the above-mentioned method for maintaining a test login status.
[0016] To achieve the fourth objective mentioned above, the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the above-mentioned method for maintaining a test login state.
[0017] Beneficial effects Compared with the prior art, the advantages of this invention are as follows: 1. Improve testing efficiency: By setting authentication tokens through session storage, the login process can be repeated, reducing test preparation time by more than 50%, especially in large-scale test case scenarios.
[0018] 2. Reduce security risks: Reduce the number of login requests to avoid triggering the target system's IP blocking, account locking and other security policies, and improve test stability.
[0019] 3. Simplify test implementation: Eliminate the need to handle complex verification steps (such as CAPTCHA) in the login process, reducing the difficulty of writing automated test scripts.
[0020] 4. Good compatibility: Based on the browser's native session storage mechanism, it is suitable for all kinds of modern browsers that support sessionStorage, and has strong adaptability. Attached Figure Description
[0021] Figure 1 This is a flowchart of the present invention. Detailed Implementation
[0022] The present invention will be further described below with reference to specific embodiments shown in the accompanying drawings.
[0023] See Figure 1 A method for testing login state persistence includes the following steps 1 to 5: Step 1. Obtain a valid authentication token and execute a complete login process. Simulate user login operations using a UI automation testing tool. After successful login, retrieve a valid authentication token (such as a token) from the browser's sessionStorage.
[0024] The core of Step 1 lies in leveraging the browser's native sessionStorage mechanism to directly write the valid authentication token (such as pds-token) obtained during the first login into the browser's session storage via an automated script. This allows subsequent test cases to inherit the login state without repeatedly executing the login process. This method breaks through the traditional "repeatedly executing login operations" model, achieving cross-test case persistence of login state by reusing authentication tokens, which is the core innovation for improving testing efficiency.
[0025] Step 2. Store the authentication token. Save the extracted authentication token to the test framework's configuration file or variable.
[0026] Step 3. Set up session storage to maintain login status. Before executing subsequent test cases, use the script execution interface provided by the UI automation testing tool to call the browser's built-in session storage setting method to write the saved authentication token into the current browser session storage.
[0027] Specifically, it involves calling the browser script via the webdriver.Firefox().execute_script() interface to execute the window.sessionStorage.setItem() operation and inject a token, combining native browser functionality with automated testing tools. This forms a feasible technical solution that balances compatibility and convenience, representing a key innovation in transforming technical concepts into practical applications.
[0028] The specific code is as follows: The corresponding WebDriver implementation example is as follows: webdriver.Firefox().execute_script(f"window.sessionStorage.setItem('pds-token', '{token}');").
[0029] Step 4. Execute the test cases. After completing the session storage settings, directly access the page that requires login permission. The browser will automatically recognize the authentication token in the session storage and maintain the user's login status without having to execute the login process again.
[0030] Step 5. Session storage cleanup: After all test cases have been executed, clear the authentication token in the browser session storage to avoid affecting subsequent tests.
[0031] This invention establishes a reusable login state maintenance link by constructing a complete process of "extracting the token upon initial login → storing the token in the local configuration → injecting the token into the session storage for subsequent tests." This mechanism ensures the effective transmission and secure storage of authentication tokens, solves the problem of token sharing among multiple test cases, and represents an innovative design at the methodological level.
[0032] As a further aspect of the present invention, in step 1, if the authentication token of the target system has an expiration date, a timed detection mechanism is set up so that when the authentication token is about to expire, the login process is automatically re-executed to obtain a new token and update the storage.
[0033] For scenarios where authentication tokens have expiration dates, a mechanism of "timed detection - automatic re-login - token update" is designed. This mechanism automatically obtains a new token and updates the session storage before the old one expires, ensuring the continued validity of the login state. This strategy overcomes the timeliness limitations of static token injection and improves the robustness of the method.
[0034] As a further aspect of the present invention, in step 3, multiple session storage key-value pairs can be set simultaneously to adapt to complex login scenarios that require multi-token authentication.
[0035] This means that it supports injecting multiple authentication-related key-value pairs into the session storage at the same time, in order to adapt to complex login scenarios that require multi-token collaborative verification (such as systems that require both token and user-id), thus expanding the applicability of the method and demonstrating the flexibility and versatility of the solution.
[0036] A test login state persistence system includes: The acquisition module is used to obtain a valid authentication token, execute a complete login process, simulate user login operations through UI automation testing tools, and retrieve the valid authentication token from the browser session storage after successful login. The storage module is used to store authentication tokens, saving the extracted authentication tokens to the test framework's configuration file or variables; The settings module is used to configure session storage to maintain login status. Before subsequent test cases are executed, the script execution interface provided by the UI automation testing tool calls the browser's built-in session storage settings method to write the saved authentication token into the current browser session storage. The execution module is used to execute test cases. After completing the session storage settings, you can directly access pages that require login permissions. The browser will automatically recognize the authentication token in the session storage and maintain the user's login status without having to execute the login process again. The cleanup module is used to clean up the session storage. After all test cases have been executed, the authentication token in the browser session storage is cleared to avoid affecting subsequent tests.
[0037] A computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the above-described method for maintaining a test login state.
[0038] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described method for maintaining a test login state.
[0039] The above are merely preferred embodiments of the present invention. It should be noted that those skilled in the art can make several modifications and improvements without departing from the structure of the present invention, and these will not affect the effectiveness of the implementation of the present invention or the practicality of the patent.
Claims
1. A method for testing login state maintenance, characterized in that, Includes the following steps: Step 1. Obtain a valid authentication token and execute a complete login process. Simulate user login operations using a UI automation testing tool. After successful login, retrieve the valid authentication token from the browser session storage. Step 2. Store the authentication token: Save the extracted authentication token to the test framework's configuration file or variable; Step 3. Set up session storage to maintain login status. Before executing subsequent test cases, use the script execution interface provided by the UI automation testing tool to call the browser's built-in session storage setting method to write the saved authentication token into the current browser session storage. Step 4. Execute the test cases. After completing the session storage settings, directly access the page that requires login permissions. The browser will automatically recognize the authentication token in the session storage and maintain the user's login status without having to execute the login process again. Step 5. Session storage cleanup: After all test cases have been executed, clear the authentication token in the browser session storage to avoid affecting subsequent tests.
2. The method for maintaining login status according to claim 1, characterized in that, In step 1, if the authentication token of the target system has an expiration period, a timed detection mechanism is set up so that when the authentication token is about to expire, the login process is automatically re-executed to obtain a new token and update the storage.
3. The method for maintaining login status according to claim 1, characterized in that, In step 1, the browser's native sessionStorage mechanism is used to write the valid authentication token obtained during the first login directly to the browser's session storage via an automated script, so that subsequent test cases can inherit the login state without having to repeat the login process.
4. The method for maintaining login status according to claim 1, characterized in that, In step 3, multiple session storage key-value pairs can be set simultaneously to adapt to complex login scenarios that require multi-token authentication.
5. A method for testing login status maintenance according to claim 1, characterized in that, In step 3, the browser script is called through the webdriver.Firefox().execute_script() interface to execute the window.sessionStorage.setItem() operation to inject the token, thus combining the browser's native functionality with the automated testing tool.
6. A system for testing login status maintenance, characterized in that, include: The acquisition module is used to obtain a valid authentication token, execute a complete login process, simulate user login operations through UI automation testing tools, and retrieve the valid authentication token from the browser session storage after successful login. The storage module is used to store authentication tokens, saving the extracted authentication tokens to the test framework's configuration file or variables; The settings module is used to configure session storage to maintain login status. Before subsequent test cases are executed, the script execution interface provided by the UI automation testing tool calls the browser's built-in session storage settings method to write the saved authentication token into the current browser session storage. The execution module is used to execute test cases. After completing the session storage settings, you can directly access pages that require login permissions. The browser will automatically recognize the authentication token in the session storage and maintain the user's login status without having to execute the login process again. The cleanup module is used to clean up the session storage. After all test cases have been executed, the authentication token in the browser session storage is cleared to avoid affecting subsequent tests.
7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements a test login status maintenance method according to any one of claims 1-7.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements a test login status maintenance method according to any one of claims 1-7.