Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Espresso:调用OpenActionBaroverFlowerOptions menu()打开菜单中的第一项_Android_Functional Testing_Android Espresso - Fatal编程技术网

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是否禁用了测试设备上的动画?