如何使用 XCUIKeyboardKey 常量?

How to use XCUIKeyboardKey constants?

XCTestXCUIElementQuery class 的正下方有许多常量,上面的文档注释指出:

    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.

显然,如注释所述,似乎应该有一个名为 typeKey:modifierFlags:XCUIElement 方法。但是,我似乎无法在文档中的任何地方找到这种方法。我也没有看到任何方法可以利用上述常量来替代这种行为。这是我有兴趣使用的常量的部分列表:

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

此代码是否为时过早,可能会在以后作为未来 Xcode 7 版本的一部分完成?

最终,我希望能够键入 cmd+a,然后使用 XCUIKeyboardKeyDelete 删除给定 XCUIElement 的内容。如果 Xcode 7 UI 测试中目前有很好的替代品,我很乐意学习知道。

--> Swift 2.0 测试版 4

您可以将 XCUIElement.typeText(text: String) 与 XCUIKeyboardKeyDelete 一起使用。

例如,当文本字段不为空时:

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

它在文档中声明方法 [XCUIElement typeKey:modifierFlags:] 仅在 macOS 上可用。参见 https://developer.apple.com/reference/xctest/xcuielement

我在虚拟 macOS 项目 UI 测试目标中的 Xcode 8.2.1 上对此进行了测试,确实存在该方法。 iOS.

上不存在