我有一个带有标签的自定义 UITableViewCell 。单元格和标签都有一个可访问性标识符,我试图断言在 UI 中至少有一个包含指定文本的单元格。我这样写断言:
EarlGrey
.selectElement(with: grey_text(self.customTestString))
.using(searchAction: grey_scrollInDirection(GREYDirection.down, 45), onElementWithMatcher: grey_kindOfClass(UILabel.self))
.assert(grey_sufficientlyVisible())
属性 customTestString 包含我要查找的字符串。我还尝试寻找我的 UITableViewCell 自定义子类,但无论如何我都遇到了这个失败:
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"
}
]
据我了解,它抱怨断言不明确,因为它可以在多个单元格上运行,但我不知道如何解决它。有什么提示吗?