【发布时间】:2015-08-15 11:06:22
【问题描述】:
我正在尝试使用 UiAutomator 为 android 应用程序(我有 apk 但没有源代码)编写 UI 自动化“黑盒”测试。 在设置阶段,我无法打开抽屉的应用程序。到目前为止,我的代码是
@Override
public void setUp() throws Exception {
super.setUp();
mDevice = UiDevice.getInstance(getInstrumentation());
mDevice.pressHome();
//Wait for the app drawer icon to show up on the screen
mDevice.wait(Until.hasObject(By.desc("Apps")), 3000);
//Obtain reference to the app drawer button in order to click it
UiObject drawerIcon = mDevice.findObject(new UiSelector().description("Apps"));
drawerIcon.clickAndWaitForNewWindow();
//Finding and Clicking on the Sunshine app
UiObject drawer = mDevice.findObject(new UiSelector().resourceId("com.sec.android.app.launcher:id/apps_grid"));
UiObject appToTest = mDevice.findObject(new UiSelector().description("app-to-test-description"));
while (!appToTest.exists()) {
drawer.swipeLeft(3);
}
appToTest.clickAndWaitForNewWindow();
}
当我运行测试时,它应该会打开应用程序(然后运行我尚未编写的各种测试方法。) 相反,它打开抽屉并挂起。我想有更好的方法来识别抽屉并滚动它直到找到正确的应用程序。 这是错误日志。
运行测试
开始试运行
android.support.test.uiautomator.UiObjectNotFoundException: UiSelector[RESOURCE_ID=com.sec.android.app.launcher:id/apps_grid] 在 android.support.test.uiautomator.UiObject.getVisibleBounds(UiObject.java:891) 在 android.support.test.uiautomator.UiObject.swipeLeft(UiObject.java:315) 在 com.crisanti.roberto.uturistautomatedtest.UiAutomatorTest.setUp(UiAutomatorTest.java:29) 在 android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191) 在 android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176) 在 android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555) 在 android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1853)
【问题讨论】:
标签: android testing android-uiautomator