如何使用浓缩咖啡按下 setPositiveButton 类型 警报对话框按钮



如果我想按添加按钮,我尝试了:

onView(withText("ADD")).perform(click())

以及

onView(withText("ADD"))
                .inRoot(isDialog()) 
                .check(matches(isDisplayed()))
                .perform(click());

但它们都不能很好地工作

在这种情况下,我将为您提供使用uiautomator,更多信息

尝试这样做

Thread.sleep(TimeUnit.SECONDS.toMillis(1));
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
UiObject obj = device.findObject(new UiSelector().textContains("ADD").clickable(true));
obj.click();

浓缩咖啡withText()区分大小写。 您在测试中检查"ADD",但在对话框构造中将值设置为"添加"。如果"ADD"直观地显示在您的UI中,这可能是由于在textView上设置了样式或文本大写,但Espresso实际上正在寻找在小部件上设置的基础文本值。

最新更新