0

I'm trying to make a test with Espresso-test-kit that makes a click on a specific element of my Listview.

I have a list and within each list item I have a button which I would like to click.

What I've tried:

onData(any(Object.class))
        .inAdapterView(withId(resId))
        .onChildView(withId(R.id.btnActionEdit))
        .perform(click());

and

onData(hasToString(startsWith("test")))
        .inAdapterView(withId(R.id.btnActionEdit))
        .perform(click());

Error:

com.google.android.apps.common.testing.ui.espresso.AmbiguousViewMatcherException: 'with id: is <2131362042>' matches multiple views in the hierarchy.

at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:579)
at com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:69)
at com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:40)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:159)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.doPerform(ViewInteraction.java:90)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.perform(ViewInteraction.java:73)
at com.google.android.apps.common.testing.ui.espresso.DataInteraction.load(DataInteraction.java:135)
at com.google.android.apps.common.testing.ui.espresso.DataInteraction.perform(DataInteraction.java:112)
at com.myapplication.EditSearchTest.test1(EditSearchTest.java:33)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onStart(GoogleInstrumentationTestRunner.java:167)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)

Someone help me?

rsicarelli
  • 1,013
  • 1
  • 11
  • 28
  • Can you post the view hierarchy? – yogurtearl Sep 16 '14 at 04:24
  • 7
    Guys, this is an `Espresso` specific question, not a duplicate of the one you mentioned. – Androiderson Sep 16 '14 at 13:53
  • Since closed questions can't be answered, in a comment: Either use a data matcher in onData() that matches the backing data of the item you want to click, or specifiy the item by its position in the listadapter by using onData().inAdapterView().atPosition(). – haffax Sep 17 '14 at 09:40

0 Answers0