Skip to content

Instantly share code, notes, and snippets.

@evermeer
Created June 1, 2018 14:13
Show Gist options
  • Save evermeer/4969d7722541e7b244d6e511bb074381 to your computer and use it in GitHub Desktop.
Save evermeer/4969d7722541e7b244d6e511bb074381 to your computer and use it in GitHub Desktop.
code block 2 for UITest medium blog
public extension RawRepresentable {
var element: XCUIElement {
if query.count > 1 {
fatalError("There are \(query.count) elements with identifier \(self.rawValue as? String ?? "") found!")
}
return query.firstMatch
}
var query: XCUIElementQuery {
return XCUIApplication().descendants(matching: .any).matching(identifier: self.rawValue as? String ?? "")
}
var count: Int {
return Int(query.count)
}
subscript(i: Int) -> XCUIElement {
return query.allElementsBoundByIndex[i]
}
var exists: Bool {
return element.exists
}
func tap() {
element.tap()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment