對於我來說,問題和泰德一樣。實際上,如果在登錄字段和硬件KB處於打開狀態後輕敲字段被輕敲,軟件鍵盤將在第二個字段輕擊時自行消失,並且它不是特定於UI測試。
經過一段時間使用AppleScript亂搞,這裏就是我想出了(改進是歡迎):
tell application "Simulator" activate tell application "System Events" try tell process "Simulator" tell menu bar 1 tell menu bar item "Hardware" tell menu "Hardware" tell menu item "Keyboard" tell menu "Keyboard" set menuItem to menu item "Connect Hardware Keyboard" tell menu item "Connect Hardware Keyboard" set checkboxStatus to value of attribute "AXMenuItemMarkChar" of menuItem if checkboxStatus is equal to "✓" then click end if end tell end tell end tell end tell end tell end tell end tell on error tell application "System Preferences" activate set securityPane to pane id "com.apple.preference.security" tell securityPane to reveal anchor "Privacy_Accessibility" display dialog "Xcode needs Universal access to disable hardware keyboard during tests(otherwise tests may fail because of focus issues)" end tell end try end tell end tell
創建代碼的腳本文件上面,並把它添加到必要的目標(可能的UI測試只有目標,您可能需要爲開發目標添加類似的腳本以在開發過程中重新啓用硬件鍵盤)。 你應該在構建階段添加Run Script
階段,像這樣使用: osascript Path/To/Script/script_name.applescript
我得到的[爲符合所述UIKeyInput協議一個UIView相同的錯誤(http://stackoverflow.com/questions/35740068/xcode -ui - 測試 - uikeyinput-的TypeText)。 – ma11hew28