onChildView and hasSiblings with Espresso

只谈情不闲聊 提交于 2019-11-29 02:09:15

Based on your last comment you should use onView() instead of onData(). I think you'll be able to click the button using hasSibling() - example

onView(allOf(withId(R.id.positive), hasSibling(withDesc(someString))))
    .perform(click());

or examples without your custom matcher (sibling view has text):

onView(allOf(withId(R.id.positive), hasSibling(withText(someString))))
    .perform(click());

or (sibling view has content description):

onView(allOf(withId(R.id.positive), hasSibling(withContentDescription(someString))))
    .perform(click());

EDITED:

OK, I'd try these two variants:

onView(allOf(withId(R.id.increaseGoalButton), isDescendantOfA(withId(R.id.timeGoalWidget))))
    .perform(click());

or

onView(allOf(withId(R.id.increaseGoalButton), withParent(withId(R.id.timeGoalWidget))))
    .perform(click());

None of your content descriptions match the string "description" that's why it doesn't find anything.

Assuming the button id is R.id.positive, and the id is unique in the current activity view, you can simply use:

onView(withId(R.id.positive)).perform(click());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!