I'm doing some automated tests in the iOS simulator using UIAutomation.
In Xcode 6, the iOS simulator's keyboard behavior changed to be similar to a real device, and now there is a menu item to connect/disconnect your Mac's keyboard to the simulator: Hardware > Keyboard > Connect Hardware Keyboard.
I don't mind this, but what happens when your Mac's keyboard is connected is that the simulator will no longer show the software keyboard. When you run a test script with UIAutomation, calls like UIATarget.localTarget().frontMostApp().keyboard().typeString("myString");
will fail because the keyboard doesn't appear, even when you've made a text field the first responder.
This is annoying, because if I do any manual testing in the simulator, I will need to remember to disable the hardware keyboard before I run any of my UIAutomation tests, or they will all fail.
Is there any way, from within a UIAutomation JS script, to check hardware keyboard settings and disable them? Or, any way to do this from the command line, prior to executing the UIAutomation script?
Click the simulator menu Hardware —> Keyboard, check the Connect Hardware Keyboard sub-menu, and then uncheck it at once. Now the keyboard will be prompted automatically when you click the text field or text view UI component in the iOS simulator. 2. Fix iOS Simulator Keyboard Hidden Issue Method Two.
Select the iOS simulator window by click it. Click the simulator menu Hardware —> Keyboard, check the Connect Hardware Keyboard sub-menu, and then uncheck it at once. Now the keyboard will be prompted automatically when you click the text field or text view UI component in the iOS simulator.
For multiple simulator support, you will need to upgrade to the XCUITest driver). To allow the iOS simulator to be automated by Instruments, you need to modify the authorization database for the system. Appium provides an easy way to do this by installing and running an authorization script: sudo authorize-ios.
Below are the steps to fix this issue. Select the iOS simulator window by click it. Click the simulator menu Hardware —> Keyboard, check the Connect Hardware Keyboard sub-menu, and then uncheck it at once. Now the keyboard will be prompted automatically when you click the text field or text view UI component in the iOS simulator.
If I understood your question correctly, you need bulletproof way to enter text. I just use setValue for that. Like this: UIATarget.localTarget().frontMostApp().textFields().Login.setValue('sofa');
Updated AppleScript of Leo's answer for Xcode 11 where "Hardware" was changed to "I/O". To get this working it Xcode 11.4.1 I needed a bash script wrapper to call the AppleScript scpt file.
Files
./disable-hardware-keyboard
./disable-hardware-keyboard.scpt
tell application "Simulator"
activate
end tell
tell application "System Events"
set hwKB to value of attribute "AXMenuItemMarkChar" of menu item "Connect Hardware Keyboard" of menu 1 of menu item "Keyboard" of menu 1 of menu bar item "I/O" of menu bar 1 of application process "Simulator"
if ((hwKB as string) is equal to "missing value") then
do shell script "echo 'hardware keyboard is off'"
else
click menu item "Connect Hardware Keyboard" of menu 1 of menu item "Keyboard" of menu 1 of menu bar item "I/O" of menu bar 1 of application process "Simulator"
end if
end tell
#!/bin/bash
cd $(dirname $0)
osascript disable-hardware-keyboard.scpt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With