Android Espresso:调用OpenActionBaroverFlowerOptions menu()打开菜单中的第一项
我有以下浓缩咖啡测试:Android Espresso:调用OpenActionBaroverFlowerOptions menu()打开菜单中的第一项,android,functional-testing,android-espresso,Android,Functional Testing,Android Espresso,我有以下浓缩咖啡测试: 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
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());
openActionBarOverflowerOptions菜单(InstrumentationRegistry.getTargetContext());
//如果我在这里执行Thread.sleep(),我可以看到菜单项已经被单击了
onView(使用文本(“登录”)/尝试:
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());
public class EspressoMatchers {
public static Matcher<View> withOverflowMenuButton() {
return anyOf(allOf(isDisplayed(), withContentDescription("More options")),
allOf(isDisplayed(), withClassName(endsWith("OverflowMenuButton"))));
}
}
那么它应该可以正常工作。只需为工具栏使用正确的ID即可。我知道这只是浓缩咖啡课上的一个副本,但我也遇到了这个问题,这对我很有帮助
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());
请记住,始终按“名称”单击菜单项,而不是按其ID,因为ID无效。因此,您的“点击项目”应该可以:
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());
onView(withText("Sign in")) //<= click on the MenuItem
.perform(click());
onView(使用文本(“登录”)//尝试:
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());
public class EspressoMatchers {
public static Matcher<View> withOverflowMenuButton() {
return anyOf(allOf(isDisplayed(), withContentDescription("More options")),
allOf(isDisplayed(), withClassName(endsWith("OverflowMenuButton"))));
}
}
那么它应该可以正常工作。只需为工具栏使用正确的ID即可。我知道这只是浓缩咖啡课上的一个副本,但我也遇到了这个问题,这对我很有帮助
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());
请记住,始终按“名称”单击菜单项,而不是按其ID,因为ID无效。因此,您的“点击项目”应该可以:
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());
onView(withText("Sign in")) //<= click on the MenuItem
.perform(click());
onView(withText(“Sign-in”)//我假设您正在测试类中使用ActivityTest规则。请尝试使用OpenActionBarOverFlowerOptions菜单(mActivityRule.getActivity())代码>我假设您正在测试类中使用ActivityTest规则。请尝试使用OpenActionBarOverFlowerOptions菜单(mActivityRule.getActivity())代码>@mbonnin是否禁用了测试设备上的动画?@mbonnin是否禁用了测试设备上的动画?