How to use XCUIKeyboardKey constants?

Just below the XCUIElementQuery class inside XCTest there are many constants where the caption above the document is higher:

  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. 

It seems that there should be an XCUIElement method called typeKey:modifierFlags: as indicated in the note. However, I cannot find this method in the documentation. I also do not see any method that replaces this behavior using the above constants. The following is an incomplete list of constants that I would like to use:

 let XCUIKeyboardKeyDelete: String let XCUIKeyboardKeyReturn: String let XCUIKeyboardKeyTab: String let XCUIKeyboardKeyCommand: String 

Is this code premature and most likely to be completed later as part of future releases of Xcode 7?

Ultimately, I would like to be able to type cmd+a , and then use XCUIKeyboardKeyDelete to delete the contents of this XCUIElement . If there are good alternatives currently available in testing the Xcode 7 user interface, I would love to know about that.

-> Swift 2.0 beta 4

+4
source share
2 answers

You can use XCUIElement.typeText (text: String) with XCUIKeyboardKeyDelete.

Example when the text field is not empty:

 textField.tapWithNumberOfTaps(2, numberOfTouches: 1) app.menuItems["Select All"].tap() textField.typeText(XCUIKeyboardKeyDelete) 
+4
source

The documentation states that the [XCUIElement typeKey:modifierFlags:] method is available only for macOS. See https://developer.apple.com/reference/xctest/xcuielement

I tested this on Xcode 8.2.1 in a dummy macOS project UI test target, and indeed, this method exists. It does not exist on iOS.

0
source

All Articles