Skip to content

Instantly share code, notes, and snippets.

@tilltue
Last active June 17, 2018 15:14
Show Gist options
  • Save tilltue/3c94d422a92c6accb8b0c95dabc0f32c to your computer and use it in GitHub Desktop.
Save tilltue/3c94d422a92c6accb8b0c95dabc0f32c to your computer and use it in GitHub Desktop.
EarlGrey Example
enum CustomMatcher {
case allOfsufficiently(id: String)
case displayLabel(text: String)
case displayButton(text: String)
var matcher: GREYMatcher {
switch self {
case let .allOfsufficiently(id):
return grey_allOf([grey_accessibilityID(id),grey_sufficientlyVisible()])
case let .displayLabel(text):
return GREYElementMatcherBlock(matchesBlock: matchesBlock(text: text), descriptionBlock: describeBlock(text: text))
case let .displayButton(text):
return GREYElementMatcherBlock(matchesBlock: matchesBlock(text: text), descriptionBlock: describeBlock(text: text))
}
}
func matchesBlock(text: String) -> MatchesBlock {
return { (element: Any?) -> Bool in
var ret = false
if case let .displayLabel(text) = self {
if let label = element as? UILabel {
ret = label.text == text
}
}else if case let .displayButton(text) = self {
if let button = element as? UIButton {
ret = button.titleLabel?.text == text
}
}
return ret
}
}
func describeBlock(text: String) -> DescribeToBlock {
return { (description: Any) -> Void in
let greyDescription = description as! GREYDescription
greyDescription.appendText("desctiption is \(type(of: self))\(text).")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment