Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android espresso testing lock and unlock screen

I am trying to write an automated test to an android application that appears when you unlock your screen using the espresso framework. I would like to add a test case to ensure that an activity appears when the screen is unlocked.

How can I programmatically lock or unlock the screen using espresso?

like image 310
Tamás Tegzes Avatar asked Sep 01 '15 16:09

Tamás Tegzes


1 Answers

I found that UiDevice has the desired methods. My final code:

UiDevice uiDevice = UiDevice.getInstance(getInstrumentation());
    try {
        uiDevice.sleep();
        Thread.sleep(1000);
        uiDevice.wakeUp();
        Thread.sleep(1000);
    } catch (RemoteException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
like image 135
Tamás Tegzes Avatar answered Oct 20 '22 11:10

Tamás Tegzes