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

assertDisplayed doesn't work when multiple views matches the text #37

Closed
Sloy opened this issue Mar 29, 2017 · 12 comments
Closed

assertDisplayed doesn't work when multiple views matches the text #37

Sloy opened this issue Mar 29, 2017 · 12 comments

Comments

@Sloy
Copy link
Member

Sloy commented Mar 29, 2017

We found a case that I think Barista should handle.
In an Activity we had multiple views with the same text "Banana", and we were doing assertDisplayed("Banana") to verify that the data had been loaded and displayed.

Espresso fails because multiple views match the condition withText().

From the perspective of someone using Barista and reading the method assertDisplayed, I think it should work. What do you guys think???

@rocboronat
Copy link
Member

Totally agree 😄

@SmasSive
Copy link
Member

Sorry but I don't understand what you are trying to say @Sloy ...
You are doing assertDisplayed("Banana") right? but Espresso fails... And AFAIK Barista is a wrapper of Espresso so, if Espresso fails, Barista should fail too.

But for sure I misunderstand something 💃

@rocboronat
Copy link
Member

Nope. The thing is why it's failing, @SmasSive . In the context @Sloy given, the app is showing "Banana" several times. As a Barista user, if I want to check if the text "Banana" is there, if there are lots of "Banana", assertDisplayed("Banana") should give a green, not an Exception.

@SmasSive
Copy link
Member

Yeah! Then I agree with you both 👯‍♂️

@rocboronat
Copy link
Member

Then... it's PR time! 🎉 hehehe

@Sloy
Copy link
Member Author

Sloy commented Mar 29, 2017

Exactly, sorry for the bad explanation 😅

"Banana" appears twice in that screen, let's say it's the title of the screen and also a TextView inside the layout.

With espresso, if you run
onView(withText(text)).check(matches(isDisplayed()));
and it finds two views with the text "Banana", it fails.

My point is: from the perspective of a Barista user, assertDisplayed() means it's displayed any number of times, the name of the method doesn't imply the other restriction.

Better @SmasSive ?

@Sloy
Copy link
Member Author

Sloy commented Mar 29, 2017

LOL I see I was too slow writing my comment, you both already answered.
:partyparrot:

@rocboronat
Copy link
Member

rocboronat commented Mar 29, 2017

Welcome to the party, @Sloy ! Take some ice! 🍸 🍹

@Sloy Sloy removed the question label Mar 29, 2017
@SmasSive
Copy link
Member

Jajaja @Sloy now your explanation is perfect!
So let's code it out!

@Sloy
Copy link
Member Author

Sloy commented Mar 29, 2017

Ideas?
We solved it by wrapping the withText("Banana") matcher inside a firstOf(withText("Banana")) matcher.
But it wouldn't work if the first banana is hidden and the second one is displayed.

Sloy added a commit that referenced this issue Mar 29, 2017
@Sloy
Copy link
Member Author

Sloy commented Mar 29, 2017

There goes my idea: #38

Sloy added a commit that referenced this issue Apr 3, 2017
Sloy added a commit that referenced this issue Apr 4, 2017
* Created test to reproduce the issue in #37

#37

* Fixed failing test with firstOf matcher

* Create failing test to reproduce wrong behavior with firstOf

* Fixed failing test by using allOf matcher

By including the isDisplayed condition as a requirement for onView, we filter any views that matches the text but are not displayed.
A bit tricky though.

* Renamed firstOf to firstViewOf

Because the usage is different from allOf. It's not a matcher filter, but a view filter.

* Remove an unneeded parenthesis

* Handle assertDisplayed for repeated texts by string resource

* Added precondition for gone view in repeated views test
@rocboronat
Copy link
Member

Done by @Sloy !

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