How to click the button zakutki in espresso testing?

I do not think this is a matter of deception. I am writing a simple espresso test, and part of it involves clicking the “Ok” button in the diner.

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()); 

It throws

android.support.test.espresso.PerformException: executing a “Single-click to view” error with the text: “Good.” Called: java.lang.RuntimeException: the action will not be executed because the target view does not meet one or more of the following restrictions : The user is given at least 90 percent of the field of view. 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-focus = false, is-focusable = true, is-layout-request = false, is-selected = false, root-is- layout-request = false, has-input-connection = false, x = 684.0, y = 53.0, text = Ok, input-type = 0, ime-target = false, has-links = false} "

Any ideas?

+7
java android android-espresso android-snackbar
source share
2 answers

RuntimeException 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 area is displayed to the user. . The problem is really due to the failure of the full view View .

The problem is caused by the race condition. You try to open a view, and while you open it, you try to click it. If the time is incorrect, less than 90% View will be available for the Espresso frame for click() . You may be able to solve the problem by turning off the animation, as recommended in the Espresso Setup Guide

  • Go to Developer Options Phone
  • Set the following
    • Window animation scale = 0.0x
    • Transition Animation Scale = 0.0x
    • Animator Duration Scale = 0.0x

My own testing shows that you can get away by simply setting the Transition Animation Scale to 0.0x . As you can imagine, this is the perfect solution for the race condition you are experiencing.

+6
source share

It can simply be found using id snackbar_action :

 onView(allOf(withId(android.support.design.R.id.snackbar_action))) .perform(click()); 
+1
source share

All Articles