私の問題はテッドの問題と同じでした。実際には、ログイン フィールドとハードウェア KB がオンの後にパスワード フィールドがタップされると、ソフトウェア キーボードは 2 回目のフィールド タップで自動的に閉じます。これは 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 テスト ターゲットのみ。開発中に HW キーボードを再度有効にするために、同様のスクリプトを開発ターゲットに追加することをお勧めします)。Run Script
ビルド フェーズにフェーズを
追加し、次のように使用する必要があります。osascript Path/To/Script/script_name.applescript