Author: Ji Yu

Intelligent testing

There are often a large number of states that need to be maintained in interactions, which can be costly to test and verify, especially when there are functional changes that require regression testing. In order to reduce the cost of development test, reinforcement learning is used to simulate user behavior in this aspect, which improves the effectiveness in two aspects:

  • Mock interface: Use the state of the learning process as test data for the service interface;
  • Regression testing: Tracing back to a specific state based on mock interface data, Puppeteer triggers front-end operations based on reinforcement learning to simulate real user behavior;

What is reinforcement learning?

Reinforcement learning is a field of machine learning that emphasizes how to maximize expected benefits by acting based on the environment. Reinforcement learning is very suitable for the e-commerce interaction mechanism that has been popular in recent years: do tasks/play games -> get different reward values -> Ultimate goal prize. In this type of interactive game, the reward is predictable and the user’s goal is to maximize their reward. This process can be abstracted as Markov decision model: the player (agent) changes the state of the game (environment) through different actions and gives different rewards to the player. This process is iterative, with the player’s ultimate goal being to maximize the reward.

Next, we use a relatively simple Q-learning to achieve similar intelligent testing purposes.

Q-learning

For different states, Q(s, A) of Q-learning stands for the expected income that can be obtained by taking action A in s state at a certain moment. The main idea of the algorithm is to construct a Q-table of state and ation to store Q value, and select the action that can obtain maximum income according to Q value. The formula for Q value is as follows:

Where, S represents state, A represents action, α represents learning rate, γ represents attenuation rate, and R represents income that action can bring.

This formula states that the Q value of the current state is formed by combining “remembered” benefits (Max Q[s’,a]) with current benefits (r). The higher the decay rate γ is, the greater the benefit effect of “memory” is. The higher the learning rate α is, the greater the influence of current interest is. The goal of Q-learning is to get an optimal sequence of actions that can get the most rewards through continuous training.

In a racing game, the player’s interactions include buying cars, building cars, doing tasks to earn coins (simplified to a single task for ease of understanding); By repeating the “action -> update state” process from the player’s initial state, the following pseudocode simply shows how we can get as perfect a Q table as possible:

// state: include class, own class, remaining gold indicates initialization Q = {}whileQ unconverged: initializes the game statewhileRace car did not reach Level 50: Use strategy π, get action A = π(S) Use Action A, get new game state update Q, Q[S,a] ← (1-α)*Q[S,a] + α*(R(S,a) + γ* Max Q[S',a]) update state stateCopy the code

Simple demo address: github.com/winniecjy/6…

Puppeteer

According to the training process of Q-learning above, we can get a series of intermediate state interfaces as mock data, which can be quickly backtraced to a specific state for testing, which is very useful in regression testing. But automated mock data alone can only do so much to improve efficiency. In 618 Interactive, the interactive team of friends and Puppeteer automate the whole process. Puppeteer is a tool engine from the Chrome team that provides a series of apis to control Chrome, automatically submitting forms, keyboarding, blocking modification requests, saving UI snapshots, and more.

With Puppeteer’s operating logic, parts can be precipitated into a general-purpose test environment, such as:

  • Different user types, such as login, non-login, risk, member, etc.;
  • Interface intercepts mock logic;
  • Page snapshot retention;
  • Page performance data retention;
  • Other common business logic, such as interactive task system, jump after a few seconds return, add points;
  • .

Popover scale

In interaction, popovers have always been an important part of visual presentation, which has a strong need for CUSTOMIZATION of UI.

The idea of a friend business is to precipitate all logic as much as possible. For e-shopping scenes, the business logic of popups can be exhausted and solidified. However, in interactive scenes, UI customization is in high demand. Therefore, the UI layer is removed and only the reusable logic is solidified, which is delivered dynamically by THE mechanism of DSL + Runtime.

Combined with this logical layer model, the presentation /UI layer can be structured accordingly. According to the dimension of project > Scene > layer, static configuration and dynamic binding can be combined with the corresponding configuration platform to achieve dynamic delivery.

conclusion

For intelligent testing, the cost of 80% of the process is relatively low. Everything from test case generation to puppeteer automated testing can be learned. The image comparison part needs more training, and the function of solidification can be explored.

For the popover scale, the internal practice of the department is to precipate the popover into a universal component, which only contains universal compatibility logic, including show/hide, the bottom scrolling prohibition of popover, multi-popover hierarchy problems, etc. For UI and other business logic, reusability is low, so it is rewritten every time. This approach maintains the commonality of components as much as possible, which is suitable for the conference line, because the popover of the conference line generally does not contain business logic (such as lottery, PK, etc.), but for the interactive line, the reused content is insignificant compared to the “weight” of the popover. The premise of the precipitation thinking of friends is that the upstream interface logic needs to be reusable, if the upstream logic can not be fixed, the front-end interactive logic is also difficult to solidify. In general, friends in the interaction of precipitation ideas are mostly from the development of efficiency, mainly for internal use; Jingdong already has similar interactive improvement schemes with the ultimate goal of profit, such as The Social Rubik’s Cube platform of Jingxi and the newly formed Sky Star platform, so they are deposited in a set of H5.

reference

[1] Puppeteer Docs, Puppeteer Docs, Puppeteer Docs


Welcome to the bump Lab blog: AOtu.io

Or pay attention to the bump Laboratory public account (AOTULabs), push the article from time to time: