Reprint Address: https://testerhome.com/topics/5650
This article was posted in Testerhome
Problem description
The problem is such a drop, our company's app login there is a step need to enter the gesture password, nine Gongge kind of, look at the following diagram:
The solution to the goal is to use Appium to automatically enter the gesture password.
Search Solutions
As a result, the online search of ready-made experience, with the following results:
I'm having problems.
According to the figure, the nine Gongge 9 points should be 9 ImageView objects, using the same uiautomator to test the app, found the reality a little backbone
Look at the picture.
Originally our company's app gesture password keyboard with Lockviewpattern, no way to get 9 point object;
That is, the online search method does not apply to the problems I encountered
Another way of thinking.
What then, then rightfully think of touchaction, using touch action behavior, directly to do the corresponding gesture. A search on the Internet will find a sample code
Touchaction.press (Beginx,beginy). MoveTo (Xstep,ystep). MoveTo (Xstep,ystep). Release (). perform ();
Although I have not been exposed to the automated testing of the app before, I've got some hints from this example code; I guess he meant to press the finger at (beingx,beginy), then move (xstep,ystep), then move (Xstep,ystep) and finally release.
Practical methods
To simplify the test, I set the gesture password to draw a straight line from top to bottom three points;
But directly with the coordinate point to find there will be some problems, such as mobile phone screen size is different, the location of the point may be biased, so the input hardcode coordinate point is absolutely not desirable; What to do, look at the picture below
At the moment, I can get the coordinates of the starting point of the upper-left corner of the Lockpatternview object (beginx,beginy), height, width; if it is a straight downward line from the middle 2nd, the x-axis coordinate of the second point is definitely BeginX + WIDTH/2, after all, is at the midpoint; its y-axis coordinates are about BeginY + HEIGHT/4; Starting from the second point, go down to the 5th and then 8th; they move about 2 of the height of the X-height; With these variable relative coordinate positions, the screen size is not feared It's changing.
Tried several screen size of different phones, have been successful
Of course this should be just one of the solutions, welcome to the other better ways
Code Reference
public static void Setlockpattern (Appiumdriver driver) throws exception{list<webelement> view = Toolkit . Waifforexistence ("//android.view.view[contains (@resource-id, ' View_lock_pattern ')]", driver);
Nine Gongge keyboard view webelement Welem = view.get (0);
int startX = Welem.getlocation (). GetX ();
int starty = Welem.getlocation (). GetY ();
int height = welem.getsize (). GetHeight ();
int width = welem.getsize (). GetWidth ();
int ystep = HEIGHT/4;
int BeginX = (2 * startX + width)/2;
int beginy = Starty + ystep;
Gesture Password Settings logger.info ("Start setting gesture password, middle vertical straight line,");
Touchaction touchAction1 = new touchaction (driver);
Touchaction1.press (Beginx,beginy). MoveTo (0,ystep). MoveTo (0,ystep). Release (). perform ();
Toolkit.wait (1);
Logger.info ("Set gesture password again, middle vertical straight line");
Touchaction1.press (Beginx,beginy). MoveTo (0,ystep). MoveTo (0,ystep). Release (). perform (); Logger.info ("Gesture password set complete");
} ===================================================================================================== a 4-point attempt. Can also, just seemingly moveto inside the step size can not have negative value, have a negative appium will error org.openqa.selenium.interactions.InvalidCoordinatesException;
Touchaction1.press (point1x,point1y). MoveTo (xstep,0). MoveTo (0,ystep). MoveTo (xstep,0). MoveTo (0,ystep). Release (). Perform ();