Created
February 12, 2018 13:55
-
-
Save Blackjacx/27d5610a02cb6c2550be3f69157c6a21 to your computer and use it in GitHub Desktop.
XCUIElement+ClearAndEnterText
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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