I don't believe that this is a dupe question. I am writing a simple Espresso test and part of it involves clicking a "Ok" button in a snackbar.
Espresso.onView(allOf(withId(android.support.design.R.id.snackbar_text), withText(R.string.permission_snackbar)))
.check(matches(isDisplayed()));
Espresso.onView(withText("Ok")).perform(click());
This throws
android.support.test.espresso.PerformException: Error performing 'single click' on view 'with text: is "Ok"'. Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints: at least 90 percent of the view's area is displayed to the user. Target view: "AppCompatButton{id=2131558552, res-name=snackbar_action, visibility=VISIBLE, width=264, height=144, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=684.0, y=53.0, text=Ok, input-type=0, ime-target=false, has-links=false}"
Any ideas?
The RuntimeException
seen here java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints: at least 90 percent of the view's area is displayed to the user.
. The issue does, in fact come from a failure of the View
to be fully displayed.
The issue is caused by a race condition. You are attempting to open the view, and during it's opening you are attempting to click it. If the timing isn't right, then less than 90% of the View
will be available for the Espresso framework to click()
. You may be able to resolve the issue by disabling animations, as recommended in The Espresso Setup Instructions
Developer Options
My own testing indicates that you can get away with just setting the Transition Animation Scale
to 0.0x
. As you can imagine, this is a perfectly consistent solution to the race condition that you're experiencing.
It can simply be found using the id snackbar_action
:
onView(allOf(withId(android.support.design.R.id.snackbar_action)))
.perform(click());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With