在Android Espresso测试中关闭警报对话框 [英] Dismiss Alert Dialog in Android Espresso Test

查看:68
本文介绍了在Android Espresso测试中关闭警报对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找解决方案,但是找不到.我正在创建一个Espresso测试,需要关闭第一次显示特定活动屏幕时出现在屏幕中间的警报对话框.对话框上没有按钮,因此要消除它,用户需要在框外的任何位置单击.有谁知道我可以用Espresso做到这一点.我尝试单击基础屏幕上的布局,但Espresso无法说在层次结构中找不到该视图.

I've looked around for solution for this but can't find one. I'm creating an Espresso Test and need to dismiss an Alert Dialog that appears in the middle of the screen the first time a particular Activity screen is displayed. There are no buttons on the dialog so to dismiss it the user needs to click anywhere outside the box. Does anyone know how I can do this with Espresso. I tried clicking on a layout on the underlying screen but Espresso fails saying that view cannot be found in the hierarchy.

推荐答案

使用onView(withText("alert_dialog_text")).perform(pressBack());,这必须关闭您的对话框.

Use onView(withText("alert_dialog_text")).perform(pressBack()); this must dismiss your dialog.

这篇关于在Android Espresso测试中关闭警报对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆