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
GREYInteraction atIndex doesn't throw an exception if index is larger than number of matched elements #419
Comments
Quick question - could you show us how you're using |
So, I'm essentially just trying to determine the number of elements of a certain type that are currently displayed. The latest version of my method (which doesn't work) is:
|
That seems like a bug in EarlGrey. Also, I notice you're using atIndex to get the count of elements. This seems to be a behavior many devs are using. We're planning to cut a release by today, this will surely be added in the next one. Thanks for reporting this. |
@jblack10101 I created this test for our main table view -
A
would be completely out of sync.
Is there a @throws or so annotation that we could use for that here? As before, the atIndex can be used only in conjunction with an action / assertion. The reason why you're not seeing any exception being thrown is because you're passing an error. The error will soak the exception and allow you to handle it yourself. In the above test I've added, if you remove the passed error, then you'll see an issue with the last statement. Is there something I'm missing from this? I'll add the test I showed in our Contribs project as a method so that you'd have a ready reference when you wish to get the count. I'm using EarlGrey v1.7.0 with Swift 2.3. |
Closing this for now. @jblack10101 do reopen and tell us if anything else is required. |
Reopening here (tell me if it is not the place to talk about this) but is related to the |
We don't do a check for visibility when we try to get the count of cells, so visibility shouldn't impact the result. We go through the hierarchy and check the count. Can you ensure using |
Counting instances of |
So I figured out what the issue is, the labels that I'm counting seems to have an |
I've tried to make a more in-depth query about this and got the following result using: let participationCells = grey_allOf([
grey_accessibilityID("BonusRecommendationRedeemedTitleID"),
GREYMatchers.matcher(forAncestor: grey_allOf([grey_kindOfClass(UIStackView.self), grey_sufficientlyVisible()]))
])
.occurrences That query finds and counts that an element has a visible EDIT: extension GREYMatcher {
/// The number of elements that satisfies the matcher.
public var occurrences: Int {
var error: NSError?
var index: Int = 0
let countMatcher: GREYElementMatcherBlock =
GREYElementMatcherBlock.matcher(matchesBlock: { (element: Any) -> Bool in
if self.matches(element) {
index += 1
}
return false
// swiftlint:disable:next multiple_closures_with_trailing_closure
}) { (description: AnyObject?) in
// swiftlint:disable:next force_cast
let greyDescription: GREYDescription = description as! GREYDescription
greyDescription.appendText("Count of Matcher")
}
EarlGreyImpl
.invoked(fromFile: #file, lineNumber: #line)
.selectElement(with: countMatcher)
.assert(grey_notNil(), error: &error)
return index
}
} |
The GREYInteraction atIndex documentation says, "In case of the index being over the number of matched elements, it throws an exception."
But the Swift declaration of atIndex doesn't indicate that it is possible to throw an exception, and it in fact doesn't throw an exception.
public func atIndex(index: UInt) -> Self!
From my testing, atIndex will always return a GREYInteraction, so how is it possible to know if the GREYInteraction that is returned is actually pointing to a valid UI element?
I'm using EarlGrey v1.7.0 with Swift 2.3.
The text was updated successfully, but these errors were encountered: