Sliding verification code login test programming example

1. Background and principle

There are two difficulties in handling the sliding verification code when logging in. The first is to find the distance that the slider needs to move, and the second is to simulate the trajectory of manual dragging. When the simulation trajectory is not very strict, you can use the method of accelerating first and then decelerating, that is, the acceleration in the first half of the distance is positive, and the acceleration in the second half is negative to simulate. The effect is still relatively good.

There are two main ways to calculate the moving distance. One is to use machine learning, first download a large number of verification code pictures from the website under test, and then manually label the data set to train a neural network. This method is costly and difficult. The other is image processing. Image processing is relatively simple. According to the pictures returned by the website, they can be divided into two categories: one is to return two pictures, one is a complete picture, and the other is a picture with gaps. In this case, as long as The gap position can be obtained by comparing the difference between the two images;

The other is to return only pictures with gaps. According to the characteristics of the pictures, such as obvious white edges near the gaps, edge detection can be done, or pattern recognition can be used to identify the position of the slider shape.

Then, the difficulty of sliding verification code can also be divided into two aspects: distance calculation and dragging trajectory. The calculation of the distance is to work hard on the picture, you can increase the picture library, make the position of the gap more random, the gap does not appear on the picture, the shape of the gap does not have to be a rectangle, it can be an irregular shape, and so on. If you drag the trajectory, you can ask to be closer to the real trajectory of human beings. This is invisible to our naked eyes and requires a lot of data for simulation. The future development trend should also use machine learning to comprehensively consider factors such as behavior trajectory, access frequency, and geographical location to make judgments.

2. Actual cases

1. Test content:

Swipe verification code when logging in to https://www.cointranquillity.com website

2. Test environment:

ubuntu18,selenium3.14.0,webdriver3

3. Idea description:

First of all, the verification code of this website only returns one picture, and the white edge of the gap in the picture is very obvious, so the method of boundary detection can be used. But in the actual testing process, I found that the login verification code gap of the website always appeared near the right side of the picture, so in this case, I did not use the image processing method, but used three fixed It is a relatively simple solution to keep trying and refreshing the verification code (each picture has three chances), usually after two to three attempts, it can be verified.

4. Code:

Finally:  The complete software testing video learning tutorial below has been sorted out and uploaded, and friends can get it for free if they need it【保证100%免费】

insert image description here

 These materials should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey. I hope it can help you too!

How to obtain interview documents:

Guess you like

Origin blog.csdn.net/wx17343624830/article/details/129992576