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.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
As Ruben already mentioned in previous answers, this looks like an issue to consider using UIAutomator. With Espresso, you can operate only inside your application context whereas UIAutomator gives you the control of your test device.
Add dependency to project's build.gradle
Following code block checks if the dialog with certain text exists in the screen, then dismisses it by pressing back button.
Note: This framework requires Android 4.3 (API level 18) or higher.
first check if the alert dialog is shown, if yes then perform pressBack click event
replace the OK text with the text displayed on dialog
Use
onView(withText("alert_dialog_text")).perform(pressBack());
this must dismiss your dialog.I tried on my end and you just need to call pressBack() . I had the same situation and this helped me a lot. If this is not helping you, we can talk and I will help you. Good luck!
Espresso can't do this.
You need to use uiautomator inside your Espresso test, add this to your project's gradle:
After your dialog appears, you can click on the screen at any coordinate:
That will close your dialog