Clicking a button in Espresso test got problem. Let's say I have two activities "Activity1" and "Activity2". Click a dialog OK button in Activity1 starts Activity2 where the button in Activity2 can't be clicked.
// The current activity in testing
// .....
onView(withText(R.string.dialog_btn_ok)).perform(click()); // go to the second activity
// The button on the second activity
onView(withId(R.id.btnMP)).check(matches(isDisplayed())); // this is ok
onView(withId(R.id.btnMP)).perform(click()); // got error here
android.support.test.espresso.PerformException: Error performing
'single click' on view 'with id: ..........
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: "Button{id=2131296390, res-name=btnMP,
visibility=VISIBLE, width=652, height=160, 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=20.0,
y=-16.0, text=Modify Parameter, input-type=0, ime-target=false,
has-links=false}"
When I change this with perform(scrollTo())
, a different error is shown.
// The button on the second activity
onView(withId(R.id.btnMP)).check(matches(isDisplayed())); // this is ok
onView(withId(R.id.btnMP)).perform(scrollTo(), click()); // got error here
android.support.test.espresso.PerformException: Error performing
'scroll to' on view 'with id ....
Caused by: java.lang.RuntimeException: Action will not be performed because the
target view does not match one or more of the following constraints:
(view has effective visibility=VISIBLE and is descendant of a: (is
assignable from class: class android.widget.ScrollView or is
assignable from class: class android.widget.HorizontalScrollView))
Target view: "Button{id=2131296390, res-name=btnMP,
visibility=VISIBLE, width=652, height=160, 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=20.0,
y=-16.0, text=Modify Parameter, input-type=0, ime-target=false,
has-links=false}" at
See Question&Answers more detail:
os