简体   繁体   English

Android espresso 测试锁定和解锁屏幕

[英]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.我正在尝试为使用 espresso 框架解锁屏幕时出现的 android 应用程序编写自动化测试。 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?如何使用 espresso 以编程方式锁定或解锁屏幕?

I found that UiDevice has the desired methods.我发现UiDevice具有所需的方法。 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();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM