这仅适用于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上工作吗?谢谢。
通过将构建工具版本更新到28.0.2(28.0.1)并将所有android支持库替换为使用androidx解决了问题