如何在Espresso中与Alertdialog交互?

问题描述 投票:0回答:1

我有一个测试,其中有一个Alertdialog,上面有一个“输入”字段和按钮“取消”(id为button2)和“确定”(id为button1)。首先,我必须在字段中输入值“ 1234”,然后单击“确定”按钮。但这对我不起作用,测试失败。

    onView(withId(R.id.input)).perform(typeText("1234"));
    closeSoftKeyboard();
    click(R.id.button1);
    Thread.sleep(5000);
testing android-espresso barista
1个回答
0
投票

您应该使用isDialog() RootMatcher

onView(withId(R.id.input))
    .inRoot(isDialog())
    .perform(typeText("1234"))
    .perform(closeSoftKeyboard());
onView(withText("Ok"))
    .inRoot(isDialog())
    .check(matches(isDisplayed()))
    .perform(click());
Thread.sleep(5000);
© www.soinside.com 2019 - 2024. All rights reserved.