Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Same Id matches multiple views in the hierarchy #49

Closed
despinola opened this issue May 4, 2017 · 4 comments
Closed

Same Id matches multiple views in the hierarchy #49

despinola opened this issue May 4, 2017 · 4 comments

Comments

@despinola
Copy link

Having a view pager with multiple fragments, we are not able to click on one of the items because they have both the same id.
When trying to get the item by id ViewMatchers.withId(R.id.offer_list_recyclerview) we get the following exception from espresso:
android.support.test.espresso.AmbiguousViewMatcherException:

The solution that we found is:

    sleep(1000);
    Espresso.onView(allOf(ViewMatchers.withId(R.id.offer_list_recyclerview), isDisplayed())).perform(new ViewAction[] {
        RecyclerViewActions.actionOnItemAtPosition(0, PerformClickAction
            .clickUsingPerformClick())
    });

With the isDisplayed() we filter the views to match only the ones that are on the screen, so other fragments doesnt influence.
Since we are doing a swipe just before clicking, we need to wait until the swipe finish so there is only one visibile (thats why we put the sleep)

Enjoy.

@rocboronat
Copy link
Member

Thanks @despinola !

rocboronat added a commit that referenced this issue May 5, 2017
rocboronat added a commit that referenced this issue May 10, 2017
* Add an Activity with a ViewPager that contains five RecyclerViews with several fruits

* Reproduce the issue #49 with tests

* Remove all tests that are also tested on RecyclerViewTest to avoid testing same behavior multiple times

* Also reproduce the issue in the method that uses the ID, not the text

* Fix the issue reproduced by the tests

* Reformat code with SquareAndroid style to pass the checkstyle rule

* Fix a Findbugs violation making a inner class static

* Avoid taking in consideration the position of the item in the nested RecyclerView tests

* Use uppercase to showcase constants at code (thanks, Checkstyle!)

* Avoid inlining the annotations
@rocboronat
Copy link
Member

Fix'd!

rocboronat added a commit that referenced this issue May 10, 2017
* Add an Activity with a ViewPager that contains five RecyclerViews with several fruits

* Reproduce the issue #49 with tests

* Remove all tests that are also tested on RecyclerViewTest to avoid testing same behavior multiple times

* Also reproduce the issue in the method that uses the ID, not the text

* Fix the issue reproduced by the tests

* Reformat code with SquareAndroid style to pass the checkstyle rule

* Fix a Findbugs violation making a inner class static

* Avoid taking in consideration the position of the item in the nested RecyclerView tests

* Use uppercase to showcase constants at code (thanks, Checkstyle!)

* Create Matchers that just match with displayed items

* Use the new matchers on all BaristaActions that interact only with the visible widgets

* Avoid inlining the annotations

* Reverse the calls to Espresso matchers to exactly meet the method name

* Remove uneeded imports
rocboronat added a commit that referenced this issue May 10, 2017
* Add an Activity with a ViewPager that contains five RecyclerViews with several fruits

* Reproduce the issue #49 with tests

* Remove all tests that are also tested on RecyclerViewTest to avoid testing same behavior multiple times

* Also reproduce the issue in the method that uses the ID, not the text

* Fix the issue reproduced by the tests

* Reformat code with SquareAndroid style to pass the checkstyle rule

* Fix a Findbugs violation making a inner class static

* Avoid taking in consideration the position of the item in the nested RecyclerView tests

* Use uppercase to showcase constants at code (thanks, Checkstyle!)

* Create Matchers that just match with displayed items

* Use the new matchers on all BaristaActions that interact only with the visible widgets

* Avoid inlining the annotations

* Reverse the calls to Espresso matchers to exactly meet the method name

* Remove uneeded imports

* Offer ViewPagerActions instead of SwipeActions, to meet Barista's naming

* Remove unneeded SwipeActions, added by a bad merge
@gilbertparreno
Copy link

It worked. Thanks!

@rocboronat
Copy link
Member

@gilbertparreno just to know, I understand you were having this using while using the last version of Barista?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants