我是robotium的新手,我试图编写一个快速且肮脏的脚本以在应用程序的所有屏幕上运行。

我主要遇到的问题是应用程序中的“主页”按钮。我已经尝试了很多选项,但是除了索引,我似乎无法单击它,这不是我想要的。

当我用hierarchyviewer签出按钮时,它看起来像这样:

Link

但是,当我尝试例如:

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();

09-09 22:47
查看更多