I have a custom UITableViewCell with a label inside. Both the cell and the label have an accessibility identifier, and I am trying to assert that in the UI there is at least one cell that contains a specified text. I am writing the assertion this way:
EarlGrey
.selectElement(with: grey_text(self.customTestString))
.using(searchAction: grey_scrollInDirection(GREYDirection.down, 45), onElementWithMatcher: grey_kindOfClass(UILabel.self))
.assert(grey_sufficientlyVisible())
The property customTestString contains the string I am looking for. I tried also to look for my UITableViewCell custom subclass but in any case I get this failure:
Exception: MultipleElementsFoundException
Exception Name: MultipleElementsFoundException
Exception Reason: Multiple UI elements matched for given criteria.
Exception with Assertion: {
"Assertion Criteria": "assertWithMatcher:matcherForSufficientlyVisible(>=0.750000)",
"Element Matcher": "((kindOfClass('UILabel') || kindOfClass('UITextField') || kindOfClass('UITextView')) && hasText('TEST_STRING'))",
"Recovery Suggestion": "Create a more specific matcher to narrow matched element"
}
Exception Details: Search action: <GREYScrollAction: 0x600001a44b40>.
Search action element matcher: kindOfClass('iComplain.ComplaintTableViewCell').
Error Trace: [
{
"Description": "Multiple elements were matched: (
"<UILabel:0x7fa653455880; AX=Y; AX.label='TEST_STRING'; AX.frame={{15, 209}, {85, 16}}; AX.activationPoint={57.5, 217}; AX.traits='UIAccessibilityTraitStaticText'; AX.focused='N'; frame={{15, 32}, {85, 16}}; alpha=1; UIE=N; text='TEST_STRING'>",
"<UILabel:0x7fa653455600; AX=Y; AX.label='TEST_STRING'; AX.frame={{15, 182}, {107.5, 20.5}}; AX.activationPoint={68.75, 192.25}; AX.traits='UIAccessibilityTraitStaticText'; AX.focused='N'; frame={{15, 5}, {107.5, 20.5}}; alpha=1; UIE=N; text='TEST_STRING'>"
). Please use selection matchers to narrow the selection down to single element.",
"Error Domain": "com.google.earlgrey.ElementInteractionErrorDomain",
"Error Code": "5",
"File Name": "GREYElementInteraction.m",
"Function Name": "-[GREYElementInteraction grey_errorForMultipleMatchingElements:withMatchedElementsIndexOutOfBounds:]",
"Line": "965",
"TestCase Class": "iComplainTests.EarlGreyComplaintUITests",
"TestCase Method": "testWriteComplaint"
}
]
As far as I understand it's complaining about the fact that the assertion is ambiguous because it can be run on multiple cells, but I don't know how to solve it. Any hint?