下面列出了android.support.test.uiautomator.UiDevice#pressHome ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* <i>The tests have to start from the screen home</i>
*/
@BeforeClass
public static void start(){
l("AbstractTest","@BeforeClass start");
UiDevice d = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
d.pressHome();
}
/**
* <i>The device should be at its initial state when all tests are done</i>
*/
@AfterClass
public static void end(){
l("AbstractTest","@AfterClass end");
UiDevice d = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
d.pressHome();
}
public static void launchCrawlerApp() {
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
device.pressHome();
FileLog.i(TAG_MAIN, "{Launch} " + Config.sCrawlerPackage);
Context context = InstrumentationRegistry.getContext();
Intent intent = context.getPackageManager().getLaunchIntentForPackage(Config.sCrawlerPackage);
context.startActivity(intent);
}
public static void launchHome() {
FileLog.i(TAG_MAIN, "{Press} Home");
UiDevice uidevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
uidevice.pressHome();
String launcherPackage = uidevice.getLauncherPackageName();
uidevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), Config.sLaunchTimeout);
}
private static void changeToHomeScreen(UiDevice uiDevice) throws InterruptedException {
uiDevice.pressHome();
Thread.sleep(WAIT_REOPEN_ACTIVITY);
}