我使用 SherlockActionBar。我有 3 个菜单项。始终显示第一个,其他有文本且没有图标,因此它们在菜单中。我运行了几次测试。第一次它工作得很好,但其他时候它失败了,因为
04-19 16:43:14.326: D/Robotium(22310): 'Disable layers' not found. Have found: 'Layer_3'
04-19 16:43:15.247: I/TestRunner(22310): ----- begin exception -----
04-19 16:43:15.267: I/TestRunner(22310): junit.framework.AssertionFailedError: Text string: 'Disable layers' is not found!
04-19 16:43:15.267: I/TestRunner(22310): at junit.framework.Assert.fail(Assert.java:47)
04-19 16:43:15.267: I/TestRunner(22310): at junit.framework.Assert.assertTrue(Assert.java:20)
04-19 16:43:15.267: I/TestRunner(22310): at com.jayway.android.robotium.solo.Clicker.clickOnText(Clicker.java:339)
04-19 16:43:15.267: I/TestRunner(22310): at com.jayway.android.robotium.solo.Clicker.clickOnMenuItem(Clicker.java:199)
04-19 16:43:15.267: I/TestRunner(22310): at com.jayway.android.robotium.solo.Solo.clickOnMenuItem(Solo.java:763)
pressMenuItem 产生相同的结果。为什么第二次启动时无法访问菜单?菜单甚至没有打开。真奇怪..
编辑:我使用最后一个机器人 4.1。代码:
View imageBehind = solo.getView(R.id.image_view_behind);
View imageTop = solo.getView(R.id.image_view_top);
solo.clickOnMenuItem(solo.getString(R.string.disable_sbl));
assertTrue(imageBehind.getVisibility() == View.GONE);
solo.clickOnMenuItem(solo.getString(R.string.disable_stl));
assertTrue(imageTop.getVisibility() == View.GONE);
solo.clickOnMenuItem(solo.getString(R.string.enable_sbl));
assertTrue(imageBehind.getVisibility() == View.VISIBLE);
solo.clickOnMenuItem(solo.getString(R.string.enable_stl));
assertTrue(imageTop.getVisibility() == View.VISIBLE);