testing - 如何与 Espresso 中的 alertdialog 交互?
问题描述
我有一个测试,其中有一个 Alertdialog,其中有一个“输入”字段和按钮“取消”(id 是 button2)和“Ok”(id 是 button1)。首先,我必须在字段中输入值“1234”,然后单击“确定”按钮。但这对我不起作用,测试失败。
onView(withId(R.id.input)).perform(typeText("1234"));
closeSoftKeyboard();
click(R.id.button1);
Thread.sleep(5000);
解决方案
您应该使用isDialog()
RootMatcher:
onView(allOf(
isDescendantOfA(withId(R.id.input)),
isAssignableFrom(EditText.class)))
.inRoot(isDialog())
.perform(typeText("1234"))
.perform(closeSoftKeyboard());
onView(withText("Ok"))
.inRoot(isDialog())
.check(matches(isDisplayed()))
.perform(click());
Thread.sleep(5000);
推荐阅读
- visual-studio-code - Visual Studio Code .vscode 目录从工作区消失
- ios - 横幅通话通知,例如 iOS 中的 WhatsApp 视频通话
- web-crawler - StormCrawler 不只抓取页面的主要内容
- java - 从外部存储中查找重复图像
- c# - WiFi Geolocation 免费API建议
- javascript - 如何将一个数组推入另一个数组
- php - 从 symfony 发送 PHP 邮件
- javafx - 使用 GraalVM 的 Windows Javafx 本机编译:错误 LNK2001
- docker - docker 中的 ASP.net 核心 gRPC 服务回复错误的 ssl 证书
- php - Laravel 5.4 中的调度程序,Crontab 无法自动工作