Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PerformException: Error performing 'single click'

I got a error when i run android espresso test:

com.google.android.apps.common.testing.ui.espresso.PerformException: Error performing 'single click' on view 'with id: is <2131034173>'.

My code is easy:

onView(withId(R.id.btn)).perform(click()); 

But there is no error with this code:

onView(withId(R.id.btn)).check(matches(isDisplayed())); 

I can not find the cause why it happen.

like image 350
Winton Hou Avatar asked Apr 22 '15 02:04

Winton Hou


2 Answers

The trick is to read the full stack-trace of the error. In the middle, there is some crucial piece of information like this:

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: "ImageView{id=2131492903, res-name=button_hamburger, desc=opens the side drawer, visibility=VISIBLE, width=64, height=64, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=6.0, y=6.0}" 

which explains the error in detail.

like image 140
Alexander Pacha Avatar answered Sep 19 '22 18:09

Alexander Pacha


Try to make sure that the soft keyboard is not showing. It can easily be closed with the closeSoftKeyboard ViewAction.

Moreover, make sure that system animations are disabled. Under Settings -> Developing Options turn off the following:

  • Window animation scale
  • Transition animation scale
  • Animator duration scale

Also, this might be caused by ANR dialogs from other apps.

There's been an issue reported here as well.

like image 34
appoll Avatar answered Sep 20 '22 18:09

appoll