How to automate unlock pattern on real phone using uiautomator?

Recently, I started learning uiautomatorto test the user interface of various Android devices. I am currently testing the Galaxy S4.

I am looking for any class or method that can be used to automate the unlock pattern that the user draws to unlock the phone. For example, I have a letter Nlike "draw template" to unlock the phone. How can I automate this unlock pattern in uiautomator?

+4
source share
3 answers

, "N" , N . , 9 , (x, y) 4 . , , .

  • "" → " ".
  • "INPUT" → " " → .

4 , ( [] , int segmentSteps) UiAutomator Framework.

- 4 , . .

script .

import android.graphics.Point;

public void unlockpatternlock() throws UiObjectNotFoundException, Exception {
    Point[] cordinates = new Point[4];
    cordinates[0] = new Point(248,1520);
    cordinates[1] = new Point(248,929);
    cordinates[2] = new Point(796,1520);
    cordinates[3] = new Point(796,929);
    getUiDevice().wakeUp();
    getUiDevice().swipe(cordinates, 10);
} 

script N-. .

+4

, , , x y.

UiDevice.getInstance().swipe(int startX, int startY, int endX, int endY, int steps)

, , - "N", 3 swipe. , .

. x y . "apps home" ( uiautomatorviewer), , , .

int steps - "" . 5 10. .

+2

, :

[1] Go to 'Settings' -> 'Developer Options'.
[2] Under 'INPUT' section -> you will find a option 'Pointer Location' -> enable that option.

, → , .

, , :

UiDevice.getInstance().swipe(390, 1138, 719, 1128, 40);

, .

, !

+1

All Articles