java - How to click contextual action bar item using Espresso framework -


i writing test case long clicks item in listview (backed cursoradapter) pull contextual action bar , has menu item allows user delete item.

i use following code:

public void testdeletefirstaccount(){     // long click     ondata(is(instanceof(cursor.class))).atposition(0).perform(longclick());      // click delete menu item     onview(withid(r.id.action_delete_account)).perform(click());      // find alert button text     onview(withtext("yes")).perform(click()); } 

however, unable click button because believe test running quickly. following error:

android.support.test.espresso.performexception: error performing 'single click' on view 'with id: com.example.android.cashcaretaker:id/action_delete_account'.

caused by: java.lang.runtimeexception: action not performed because target view not match 1 or more of following constraints: @ least 90 percent of view's area displayed user.

the reason believe test quick because if add thread.sleep() after long click, work fine. did test verify suspicions, i'm not sure stopping ui proper way move forward.

i have tried adding getinstrumentation().waitforidlesync() had no success.

am doing else wrong? proper way use espresso click cab item?

perhaps view still being animated @ moment espresso tries click contextualactionbar item. , if set timeout, animation has time finish , view displayed time click performed.

have tried disabling animations in test device stated in espresso setup guide?