我有下面的咖啡测试:咖啡:调用openActionBarOverflowOrOptionsMenu()在菜单中打开的第一个项目
openActionBarOverflowOrOptionsMenu(InstrumentationRegistry.getTargetContext());
// if I Thread.sleep() here, I can see that the MenuItem has been clicked already
onView(withText("Sign in")) //<= click on the MenuItem
.perform(click());
onView(withId(R.id.signupButton)) //<= click the signup button in my UI
.perform(click());
第一行那里打开溢出菜单,并在同一时间点击第一项(其中恰好是签名项目)。所以测试失败,因为它找不到MenuItem视图。有什么我做错了吗?我正在使用模拟器API 22,编译targetSdk 24并使用espresso 2.2.1。
我想你正在测试类中使用ActivityTest规则。请尝试使用'openActionBarOverflowOrOptionsMenu(mActivityRule.getActivity());' – piotrek1543
同样的问题:-( – mbonnin