Skip to content

Instantly share code, notes, and snippets.

@Blackjacx
Created February 12, 2018 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Blackjacx/27d5610a02cb6c2550be3f69157c6a21 to your computer and use it in GitHub Desktop.
Save Blackjacx/27d5610a02cb6c2550be3f69157c6a21 to your computer and use it in GitHub Desktop.
XCUIElement+ClearAndEnterText
extension XCUIElement {
/**
Removes any current text in the field before typing in the new value
- Parameter text: the text to enter into the field
*/
func clearAndEnterText(text: String) {
defer {
self.typeText(text)
}
guard let stringValue = self.value as? String else {
return
}
self.tap()
let deleteString = stringValue.flatMap { _ in XCUIKeyboardKey.delete.rawValue }.joined()
self.typeText(deleteString)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment