Open whoyawn opened 4 years ago
Since the matcher is on the test side, the element returned is an EDOObject - the UIView wrapped as an IPC object EarlGrey uses to communicate between the two XCUITest processes.
You could print the element's class to check. Use grey_kindOfClass() before the matcher you are using to get this to work. We use an internal implementation to get it to work.
Does that mean this example code won't work then?
Facing similar problem, i am trying to implement below custom matcher
public func grey_accessibilityLabelContains(text subString: String, _ ignoreCase: Bool = true) -> GREYMatcher {
let matches: GREYMatchesBlock = { (element: Any) -> Bool in
let viewElement = element as? UIView
guard let label: String = viewElement?.accessibilityLabel else { return false }
return ignoreCase ? label.localizedCaseInsensitiveContains(subString) : label.contains(subString)
}
let description: GREYDescribeToBlock = { (description: GREYDescription!) -> Void in
guard let description = description else {
return
}
let descriptionText:String = "accessibility label contains text " + subString + " with case ignorance " + ignoreCase.description
description.appendText(descriptionText)
}
return GREYElementMatcherBlock.init(matchesBlock: matches, descriptionBlock: description)
}
is there any update for this ??
In general, do not do class checks in custom matchers / assertions. You can do them on the preceding matcher. @joolurik what was the issue with your code? It should work fine, unless if it wasn't able to convert into a UIView.
Tested custom matcher in the example project, fails:
Error message:
Originally posted by @whoyawn in https://github.com/google/EarlGrey/issues/1281#issuecomment-617482793