以编程方式禁用 iOS 模拟器“连接硬件键盘" [英] disable iOS simulator 'connect hardware keyboard' programmatically
问题描述
我正在为视图编写 XCUITests 有 2 个 UITextField,并且模拟器默认连接了硬件键盘,因此没有显示软件.
是否可以在测试运行之前设置一些设置(可能在架构中?)以强制禁用模拟器连接的硬件键盘.
我浏览了几个链接,但似乎没有任何帮助.
现在这是我添加到我的 ui 测试方案中的处方.阅读脚本中的注释以获得进一步的解释.
killall 模拟器默认写入 com.apple.iphonesimulator ConnectHardwareKeyboard -bool false
工作原理首先模拟器被杀死.接下来,defaults"命令将键/值写入模拟器 plist.现在,当测试开始时,他们会启动模拟器,该模拟器会考虑我们在 plist 中写入的值.
希望它也适用于您.:)
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
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
Now here is the prescript I added to my ui tests scheme. Read the comments in script for further explanation.
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. :)
这篇关于以编程方式禁用 iOS 模拟器“连接硬件键盘"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!