在Android API 28模拟器点击问题上进行Espresso测试

时间:2018-08-29 19:42:32

标签: android testing android-espresso

仅在api级为28的Android设备上。 单击微调框后尝试匹配文本失败。

两种方法,一种是寻找不是活动的窗口,第二种是寻找弹出菜单:

...
    // 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上不起作用吗?谢谢。

1 个答案:

答案 0 :(得分:1)

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