使用Espresso在ListView内执行单击按钮

时间:2014-09-15 21:16:39

标签: android android-espresso

我尝试使用Espresso-test-kit进行测试,点击我的Listview的特定元素。

我有一个列表,在每个列表项中我都有一个按钮,我想点击。

我尝试过的事情:

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

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

错误:

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)

有人帮助我吗?

0 个答案:

没有答案