我是 robotium
的新手,我正在尝试编写一个快速但粗略的脚本来运行应用程序中的所有屏幕。
我的问题主要与应用程序中的“主页按钮”有关。我已经尝试了很多选项,但我似乎无法让它点击那里,除了索引,这不是我想要的。
当我使用 hierarchyviewer
查看按钮时,它看起来像这样:
但是当我尝试例如:
assertTrue(
"Wait for text (id: myapp.R.id.home) failed.",
solo.waitForImageById("myapp.R.id.home", 20000));
solo.clickOnImage((ImageView) solo.findViewById("myapp.R.id.home"));
solo.waitForActivity("MenuActivity");
它在 waitForImageByID
行失败。我尝试了多个选项,例如 waitForImageButton
等,但我似乎无法点击它。我在这里缺少什么?
junit.framework.AssertionFailedError: View with id: '0' is not found!
at com.jayway.android.robotium.solo.Solo.getView(Solo.java:1990)
at com.jayway.android.robotium.solo.Solo.getView(Solo.java:1970)
at com.bitbar.recorder.extensions.OtherUtils.a(OtherUtils.java:246)
at com.bitbar.recorder.extensions.OtherUtils.b(OtherUtils.java:241)
at com.bitbar.recorder.extensions.v.a(Waiter.java:71)
at com.bitbar.recorder.extensions.ExtSolo.waitForImageButtonById(ExtSolo.java:4176)
at com.example.android.apis.test.Test.testRecorded(Test.java:137)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1740)
最佳答案
使用下面这行来按下操作栏中的主页按钮
solo.clickOnActionBarHomeButton();
关于java - Robotium - 试图点击应用程序中的主页按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20661264/