场景: 启动应用 使用“后退”按钮将应用程序移至后台 睡觉 再次启动应用程序
我想使用espresso执行上述步骤,但是当我调用pressBackUnconditionally()使应用程序进入后台时,espresso测试已完成且失败。有什么方法可以继续进行测试,并且我可以使用espresso将应用程序带到前台/后台
代码段:
public void app_foreground_background(int sleeptime, int overalltimeinmins) throws InterruptedException {
long sleeptimeforscenario = sleeptime * 60000;
long now = System.currentTimeMillis();
long futureTime = now + overalltimeinmins * 60000;
try {
Espresso.pressBackUnconditionally();
while (futureTime > now) {
String command = "adb -s " + DEVICE ID + " shell am start -n activity”
getInstrumentation().getUiAutomation().executeShellCommand(
command);
Espresso.pressBackUnconditionally();
Thread.sleep(sleeptimeforscenario);
now = System.currentTimeMillis();
}
} catch (Exception e) {
e.printStackTrace();
}
}