Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

swift - disable iOS simulator 'connect hardware keyboard' programmatically

I'm writing XCUITests for view has 2 UITextField and by defualt the simulator has hardware keyboard connected, hence the software one is not being presented.

Is it possible to set some settings (maybe in schema?) to force-disable connecting hardware keyboard by the simulator before test runs.

I went through few links but none seems to be helpful. iOS simulator - disable connect hardware keyboard programmatically

Disable Hardware Keyboard for iOS Simulator using UIAutomation

When i try this on xcode local it works but, XCUItest runs on CI and i configured fastlane file for this called enable keyboard script before Test execution starts. But it throws error

Set: Entry, ":DevicePreferences::ConnectHardwareKeyboard ", Does Not Exist

Any help would be really appreciated

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Went through the same problem. Found a simple solution to add a prescript in the UI tests scheme.

First, this is image of the plist file opened with Xcode. This is located at ~/Library/Preferences/com.apple.iphonesimulator.plist

enter image description here

Now here is the prescript I added to my ui tests scheme. Read the comments in script for further explanation.

enter image description here

killall Simulator
defaults write com.apple.iphonesimulator ConnectHardwareKeyboard -bool false

How it works First the simulator is killed. Next the "defaults" command writes the key/value into the simulators plist. Now when the tests start, they launch the simulator which takes into account the value we wrote in plist.

Hope it works for you too. :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...