Just below the XCUIElementQuery
class inside XCTest
there are many constants where the documentation note above it states:
Constants for use with -[XCUIElement typeKey:modifierFlags:],
representing keys that have no textual representation. These comprise
the set of control, function, and modifier keys found on most keyboards.
Apparently, it seems there should be a XCUIElement
method called typeKey:modifierFlags:
, as the note states. However, I can't seem to find this method anywhere in the documentation. I also don't see any method that substitutes this behavior, utilizing the aforementioned constants. Here is a partial list of the constants I'd be interested in using:
let XCUIKeyboardKeyDelete: String
let XCUIKeyboardKeyReturn: String
let XCUIKeyboardKeyTab: String
let XCUIKeyboardKeyCommand: String
Is this code just premature and will likely be completed later, as part of future Xcode 7 releases?
Ultimately, I'd like to be able to type cmd+a
then use XCUIKeyboardKeyDelete
to delete the contents of the given XCUIElement
. If there are good alternatives currently available in Xcode 7 UI Testing, I'd love to learn know.
--> Swift 2.0 beta 4
You can use XCUIElement.typeText(text: String) with XCUIKeyboardKeyDelete.
Example, when a text field is not empty:
textField.tapWithNumberOfTaps(2, numberOfTouches: 1)
app.menuItems["Select All"].tap()
textField.typeText(XCUIKeyboardKeyDelete)
It states in the documentation that the method [XCUIElement typeKey:modifierFlags:]
is available on macOS only. See https://developer.apple.com/reference/xctest/xcuielement
I tested this out on Xcode 8.2.1 in a dummy macOS project UI Testing target, and indeed the method is existing. It does not exist on iOS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With