Unlimited cookie extension scheme

Author: Jingdong Technology Liu Clean

1. Pain points (*)

There are two forms of automated testing, interface automation and UI automation. However, UI automation is often blocked by login nodes, such as verification codes, graphics, sliders, etc. Although there are some ways to identify graphics and locate slider positions, the success rate is not high, and automation execution cannot be truly realized; and the http interface If the automated test front relies on cookies, it cannot be automated.

a. How to bypass login and realize automatic execution from front-end to back-end

b. In the face of complex login verification, cookies cannot be directly and automatically obtained, and manual login is required, and cookies are time-sensitive and cannot be used for a long time

This solution will effectively solve the above problems. In the face of complex login verification and cookie aging mode, you can change the short-term cookie to long-term effective, and truly realize UI automation and interface automation that relies on cookie authentication.

2. What is a cookie?

Cookie is called session tracking technology, which is a small text file that is stored on the user's machine by the browser. Cookies are plain text and have no executable code. Store some information needed by the server. Every time a site is requested, a corresponding cookie will be sent. These cookies can be used to identify user identity information, etc.

3. How to view the expiration time

Open your browser and go to the website for which you wish to view cookies.

Press F12 to open your browser's developer tools.

In the Developer Tools, Debug Tools tab, click the Store button.

In the "Site Data" list on the left, click "Cookies".

In the Values ​​list on the right, look at the Expires or Max-Age field for each cookie. These fields show when the cookie will expire.

4. Cookie mechanism

The client sends a request to the server--"The server sends an HttpResponse response to the client, which contains the header of Set-Cookie--"The client saves the cookie, and when it sends a request to the server, the HttpRequest request will contain a Cookie Header--"The server returns the response data

Time limit: Each cookie has a time limit, the default validity period is, session level: when the browser is closed, the cookie will be destroyed immediately, but we can also manually set the cookie expiration time when storing

5. Unlimited cookie extension scheme (*)

5-1. Prerequisites

a. The login node has a verification mechanism, such as SMS verification code, graphic recognition, slider and other verification;

b. The cookie has a time limit, and if the time limit expires, you need to log in again;

c. The same account will not log out or log in on multiple platforms

5-2. Implementation principle

This solution is to provide an interface through a microservice for automatic calls, and return a permanent cookie by passing the account number, embed this step into the automation process, replace the node that logs in and obtain the cookie, and permanently prolongs the time limit of the cookie, which will not Timeliness to ensure the normal execution of the subsequent automation process in a permanent cycle.

5-3. Core process steps

Step 1: Manually log in first, get the cookie from the header, and save the cookie and the aging value on the microservice platform (one account only needs to be manually logged in once, and subsequent login operations are never required).

Step 2: The microservice platform persistently stores the account, cookie, aging value, and associated business interface, and follows up the aging value to calculate the polling duration, and triggers the execution of the polling task. The task will carry this cookie to call The business interface maintains a long session, and the hold process waits. When the polling time is reached, the task execution continues, and the hold process waits again, and the loop continues to ensure that the session of the cookie is permanently maintained.

Step 3: Before the automation task is executed, the microservice interface will be called, the permanent cookie will be obtained through the account, and the follow-up automation task will be carried out with this cookie.

6. Landing cases

At present, through the following scheme, the purpose of configuring cookies once and using them for a long time has been realized.

Comparison of practical effects

Before: Cookies often expired during ui automation and http interface automation, requiring manual re-login and updating cookies on the automation platform, which is cumbersome and affects the success rate of automatic execution in the early morning

Now: After using the above solution, you only need to manually configure the cookie once on the cookie microservice platform, and you no longer need to update the cookie in the future

7. Patent description

https://zhuanli.tianyancha.com/811840799431036187d34680d5b10ae3

{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/4090830/blog/8591413