执行 XCUI 测试时更改模拟器键盘

Change simulator keyboard when performing XCUI tests

在我的 mac mini 上,我为我的键盘设置了 2 种不同的语言:英语和西班牙语。原因是因为我使用的是西班牙语键盘。但是,当我编写代码和 运行 UITest 时,他们使用的语言是英语。

当我 运行 模拟器时,我的问题就来了。键盘语言设置是在我的 mac mini 上设置的,所以当我试图找到软键盘 return 按钮时 "Next" 我是这样做的:

configuration.app.keyboards.buttons["Next"].tap().

由于键盘自动设置为西班牙语,所以找不到按钮,因为在本例中是:

configuration.app.keyboards.buttons["Siguiente"].tap()

要通过 UITest,我需要更改 mac mini 上的键盘语言,这很烦人。 运行ning UITests.

时有没有办法将英语设置为标准键盘

谢谢。

这个按钮应该有一个标识符——例如"Search" 键盘上的按钮始终具有所有键盘本地化的 Search 标识符。

"Shift" 密钥标识为 shift.

"Symbols" 作为 more.

"Next" 键为 "Next:" – 非常出乎意料 =)

您可以点击此按钮

configuration.app.keyboards.buttons["Next:"].tap()

您应该使用 print(configuration.app.debugDescription) 来查找您需要的标识符。

我一直在调查发生了什么。完成后

po print(app.debugDescription)

我看到了

    t =    25.70s Snapshot accessibility hierarchy for app with pid 29553
    t =    26.08s Snapshot accessibility hierarchy for app with pid 29553
Optional(Attributes: Application, pid: 29553, label: 'Some'
Element subtree:
 →Application, 0x600003f74b60, pid: 29553, label: 'Some'
    Window (Main), 0x600003f40700, {{0.0, 0.0}, {375.0, 812.0}}
      Other, 0x600003f40540, {{0.0, 0.0}, {375.0, 812.0}}
        Other, 0x600003f0a300, {{0.0, 0.0}, {375.0, 812.0}}
          Other, 0x600003f00700, {{0.0, 0.0}, {375.0, 812.0}}
            Other, 0x600003f74a80, {{0.0, 0.0}, {375.0, 812.0}}
              ScrollView, 0x600003f74c40, {{0.0, 44.0}, {375.0, 734.0}}
                Other, 0x600003f5a4c0, {{0.0, 44.0}, {375.0, 734.0}}
                  Image, 0x600003f5a840, {{62.7, 191.7}, {250.0, 72.0}}, identifier: 'General-logo'
                  Other, 0x600003f5a920, {{16.0, 295.7}, {343.0, 104.0}}
                    TextField, 0x600003f92ca0, {{16.0, 295.7}, {343.0, 52.0}}, placeholderValue: 'Email', value: johnsmith@Some..., Keyboard Focused
                      Button, 0x600003f5aae0, {{335.0, 312.7}, {19.0, 19.0}}, label: 'Clear text'
                    SecureTextField, 0x600003f5abc0, {{16.0, 347.7}, {343.0, 52.0}}, placeholderValue: 'Password'
                  Button, 0x600003f924c0, {{16.0, 431.7}, {343.0, 44.0}}, label: 'Log In', Disabled
                  Button, 0x600003f925a0, {{233.0, 491.7}, {126.0, 30.0}}, label: 'Forgot password?'
                  Other, 0x600003f0a3e0, {{0.0, 734.0}, {375.0, 44.0}}
                    Other, 0x600003f92680, {{0.0, 734.0}, {375.0, 0.7}}
                    Other, 0x600003f92760, {{87.0, 742.0}, {201.0, 28.0}}
                      StaticText, 0x600003f92840, {{87.0, 742.0}, {144.0, 28.0}}, label: 'Don’t have an account?'
                      Button, 0x600003f92920, {{239.0, 742.0}, {49.0, 28.0}}, label: 'Sign Up'
    Window, 0x600003f0a4c0, {{0.0, 0.0}, {375.0, 812.0}}
      Other, 0x600003f407e0, {{0.0, 0.0}, {375.0, 812.0}}
        Other, 0x600003f0a5a0, {{0.0, 477.0}, {375.0, 335.0}}
          Other, 0x600003f63100, {{0.0, 477.0}, {375.0, 277.0}}
    Window, 0x600003f40fc0, {{0.0, 0.0}, {375.0, 812.0}}
      StatusBar, 0x600003f410a0, {{0.0, 0.0}, {375.0, 44.0}}
        Other, 0x600003f41180, {{0.0, 0.0}, {375.0, 44.0}}
          Other, 0x600003f41260, {{0.0, 0.0}, {375.0, 44.0}}
            Other, 0x600003f41340, {{6.0, -4.3}, {179.7, 10.7}}
            Other, 0x600003f41420, {{190.7, -4.3}, {179.3, 10.7}}
            Other, 0x600003f41500, {{6.0, 17.7}, {179.7, 10.7}}
            Other, 0x600003f415e0, {{13.3, 14.7}, {66.7, 13.7}}
              StaticText, 0x600003f416c0, {{30.0, 14.0}, {33.3, 18.0}}, label: '2:59 PM'
            Other, 0x600003f417a0, {{21.7, 8.7}, {54.7, 21.3}}
            Other, 0x600003f41880, {{190.7, 17.7}, {179.3, 10.7}}
            Other, 0x600003f41960, {{294.0, 14.7}, {66.7, 13.7}}
              Other, 0x600003f41a40, {{294.0, 17.7}, {17.0, 10.7}}, label: 'Cellular', value: No signal
              Other, 0x600003f41b20, {{316.0, 17.3}, {15.3, 11.0}}, identifier: '3 of 3 Wi-Fi bars', value: SSID, 3 of 3 Wi-Fi...
              Other, 0x600003f41c00, {{336.3, 17.3}, {24.3, 11.3}}, label: '100% battery power', value: Not charging
            Other, 0x600003f41ce0, {{294.0, 14.7}, {66.7, 13.7}}
          Other, 0x600003f41dc0, {{8.7, 24.7}, {81.3, 13.3}}
    Window, 0x600003f41ea0, {{-0.0, -0.0}, {375.0, 812.0}}
      Other, 0x600003f41f80, {{-0.0, -0.0}, {375.0, 812.0}}
        Other, 0x600003f42060, {{-0.0, 477.0}, {375.0, 335.0}}
          Other, 0x600003f42140, {{-0.0, 477.0}, {375.0, 277.0}}
            Other, 0x600003f42220, {{-0.0, 477.0}, {375.0, 335.0}}
              Other, 0x600003f42300, {{-0.0, 477.0}, {375.0, 335.0}}
                Other, 0x600003f423e0, {{-0.0, 477.0}, {375.0, 335.0}}
          Other, 0x600003f424c0, {{-0.0, 477.0}, {375.0, 277.0}}
            Keyboard, 0x600003f425a0, {{-0.0, 477.0}, {375.0, 277.0}}
              Other, 0x600003f42680, {{-0.0, 477.0}, {375.0, 277.0}}
                Other, 0x600003f42760, {{-0.0, 477.0}, {375.0, 44.0}}, label: 'Typing Predictions'
                  Other, 0x600003f42840, {{-0.0, 477.0}, {375.0, 44.0}}
                    Image, 0x600003f42920, {{-0.0, 477.0}, {375.0, 44.0}}
                  Other, 0x600003f42a00, {{-0.0, 477.0}, {123.0, 44.0}}
                  Other, 0x600003f42ae0, {{125.0, 477.0}, {125.0, 44.0}}
                  Other, 0x600003f42bc0, {{252.0, 477.0}, {123.0, 44.0}}
                  Other, 0x600003f42ca0, {{123.0, 491.0}, {1.0, 25.0}}
                  Other, 0x600003f42d80, {{250.0, 491.0}, {1.0, 25.0}}
                Other, 0x600003f42e60, {{-0.0, 521.0}, {375.0, 233.0}}
                  Key, 0x600003f42f40, {{-0.0, 528.0}, {37.5, 46.0}}, label: 'q'
                  Key, 0x600003f43020, {{37.5, 528.0}, {37.5, 46.0}}, label: 'w'
                  Key, 0x600003f43100, {{75.0, 528.0}, {37.5, 46.0}}, label: 'e'
                  Key, 0x600003f431e0, {{112.5, 528.0}, {37.5, 46.0}}, label: 'r'
                  Key, 0x600003f432c0, {{150.0, 528.0}, {37.5, 46.0}}, label: 't'
                  Key, 0x600003f433a0, {{187.5, 528.0}, {37.5, 46.0}}, label: 'y'
                  Key, 0x600003f43480, {{225.0, 528.0}, {37.5, 46.0}}, label: 'u'
                  Key, 0x600003f43560, {{262.5, 528.0}, {37.5, 46.0}}, label: 'i'
                  Key, 0x600003f43640, {{300.0, 528.0}, {37.5, 46.0}}, label: 'o'
                  Key, 0x600003f43720, {{337.5, 528.0}, {37.5, 46.0}}, label: 'p'
                  Key, 0x600003f43800, {{-0.0, 582.0}, {37.5, 46.0}}, label: 'a'
                  Key, 0x600003f438e0, {{37.5, 582.0}, {37.5, 46.0}}, label: 's'
                  Key, 0x600003f439c0, {{75.0, 582.0}, {37.5, 46.0}}, label: 'd'
                  Key, 0x600003f43aa0, {{112.5, 582.0}, {37.5, 46.0}}, label: 'f'
                  Key, 0x600003f43b80, {{150.0, 582.0}, {37.5, 46.0}}, label: 'g'
                  Key, 0x600003f43c60, {{187.5, 582.0}, {37.5, 46.0}}, label: 'h'
                  Key, 0x600003f43d40, {{225.0, 582.0}, {37.5, 46.0}}, label: 'j'
                  Key, 0x600003f43e20, {{262.5, 582.0}, {37.5, 46.0}}, label: 'k'
                  Key, 0x600003f43f00, {{300.0, 582.0}, {37.5, 46.0}}, label: 'l'
                  Key, 0x600003f0c0e0, {{337.5, 582.0}, {37.5, 46.0}}, label: 'ñ'
                  Button, 0x600003f06ae0, {{-0.0, 636.0}, {48.0, 46.0}}, identifier: 'shift', label: 'mayúsculas'
                  Key, 0x600003f06920, {{56.0, 636.0}, {37.5, 46.0}}, label: 'z'
                  Key, 0x600003f06a00, {{93.5, 636.0}, {37.5, 46.0}}, label: 'x'
                  Key, 0x600003f06bc0, {{131.0, 636.0}, {37.5, 46.0}}, label: 'c'
                  Key, 0x600003f15b20, {{169.0, 636.0}, {37.5, 46.0}}, label: 'v'
                  Key, 0x600003f94000, {{206.5, 636.0}, {37.5, 46.0}}, label: 'b'
                  Key, 0x600003f940e0, {{244.0, 636.0}, {37.5, 46.0}}, label: 'n'
                  Key, 0x600003f941c0, {{281.5, 636.0}, {37.5, 46.0}}, label: 'm'
                  Key, 0x600003f942a0, {{327.0, 636.0}, {48.0, 46.0}}, identifier: 'delete', label: 'Suprimir'
                  Key, 0x600003f94380, {{-0.0, 690.0}, {93.5, 46.0}}, identifier: 'more', label: 'más, números'
                  Key, 0x600003f94460, {{93.0, 690.0}, {94.5, 46.0}}, label: 'espacio'
                  Key, 0x600003f94540, {{187.5, 690.0}, {47.0, 46.0}}, label: '@'
                  Key, 0x600003f94620, {{234.5, 690.0}, {47.0, 46.0}}, label: '.'
                  Button, 0x600003f94700, {{281.5, 690.0}, {93.5, 46.0}}, identifier: 'Next:', label: 'Siguiente'
          Other, 0x600003f947e0, {{-0.0, 477.0}, {375.0, 335.0}}
            Button, 0x600003f948c0, {{-0.0, 745.0}, {66.0, 66.0}}, label: 'Next keyboard', value: English (US)
            Button, 0x600003f949a0, {{309.0, 745.0}, {66.0, 66.0}}, identifier: 'dictation', label: 'Dictate'
              StaticText, 0x600003f94a80, {{309.0, 745.0}, {0.0, 0.0}}
              Image, 0x600003f94b60, {{334.0, 761.0}, {15.0, 25.0}}, identifier: 'dictation_dockitem-portrait'
Path to element:
 →Application, pid: 29553, label: 'Some'
Query chain:
 →Find: Target Application 'some'
  Output: {
    Application, pid: 29553, label: 'Some'
  }
)

根据 Smart Monkey 的建议,我找到的位置:

Button, 0x600003f94700, {{281.5, 690.0}, {93.5, 46.0}}, identifier: 'Next:', label: 'Siguiente'

烦人的部分是不一致。例如,按钮 "Go":

Button, 0x600003f98460, {{281.5, 690.0}, {93.5, 46.0}}, identifier: 'Go', label: 'Ir', Disabled

标识符上没有“:”...