XCode UITest不会给NSTextField键盘焦点

时间:2017-07-26 18:46:44

标签: swift xcode macos xctest uitest

所以我点击一个菜单项就会出现一个窗口。通常情况下,第一个textBox会立即获得键盘焦点,但在UITest中,窗口中没有任何东西可以获得键盘焦点(没有焦点环)。这是有问题的,因为它阻止我使用malloc

键入文本字段

我在窗口和文本框上尝试std::vector尝试给它焦点,但似乎没有任何东西使窗口或文本框成为焦点。 任何帮助将不胜感激

实施例

std::vector

作为旁注,我已经确认我查询的所有元素确实存在。

编辑:

我通过字面上的垃圾邮件textField.typeText("someText")让它工作,直到它改变了给定文本框的值,如

.click()

然而,这种方法很糟糕,除了启发式(大约15-30s)之外我无法真正抽出时间,所以我希望有人可以帮助解释确保关注文本框的更好方法,或至少解释一下我最初做错了什么。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

以下是两个可能的想法:

  1. 为您尝试与之交互的对象分配辅助功能ID,并尝试通过辅助功能ID对其进行寻址。来自https://blog.metova.com/guide-xcode-ui-test
  2. For element identification there is additionally elementMatchingPredicate(NSPredicate) and elementMatchingType(XCUIElementType, identifier: String?).

    These are separate from containingPredicate(NSPredicate) and containingType(XCUIElementType, identifier: String?) which are checking the element for items inside it whereas the elementMatching... options are checking the values on the element itself. Finding the correct element will often include combinations of several query attributes.

    1. 在“系统偏好设置”中启用辅助功能此处所述的辅助功能:https://support.apple.com/en-us/HT204434然后发送键盘命令以设置焦点。
相关问题