Espresso 测试 Android API 28 个模拟器点击问题

Espresso testing on Android API 28 emulator click issue

这仅适用于 Android 级别为 api 28 级的设备。 单击微调器后尝试匹配文本失败。

两种方法,一种是寻找 window 而不是 activity,第二种是寻找弹出菜单:

...
    // Look for text "Green" in the menu
    onView(withId(getFieldId(COLOR_ID))).perform(click());
    onView(withText("Green"))
            .inRoot(withDecorView(not(is(rule.getActivity().getWindow().getDecorView())))) // Look for popup menu
            .perform(click());

    // Second spinner, Look for the text "Medium"
    onView(withId(getFieldId(SIZE_ID))).perform(click());
    onView(withText("Medium")).inRoot(RootMatchers.isPlatformPopup()).perform(click());
...

两者都适用于设备 API <=27

知道为什么这不适用于 28 吗?谢谢。

通过将构建工具版本更新为 28.0.2(原为 28.0.1)并替换所有 android 支持库以使用 androidx

解决了问题