以编程方式禁用iOS模拟器“连接硬件键盘" [英] disable iOS simulator 'connect hardware keyboard' programmatically

查看:307
本文介绍了以编程方式禁用iOS模拟器“连接硬件键盘"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为视图编写XCUITests,它具有2个UITextField,并且通过默认设置,模拟器已连接了硬件键盘,因此没有提供软件.

是否可以设置某些设置(也许在模式中?)以在测试运行之前通过模拟器强制禁用连接硬件键盘.

我通过的链接很少,但似乎没有帮助. iOS模拟器-以编程方式禁用连接硬件键盘

使用UIAutomation禁用iOS模拟器的硬件键盘

当我在xcode local上尝试此方法时,它可以工作,但是,XCUItest在CI上运行,并且在测试执行开始之前,我为此调用的键盘键盘配置了fastlane文件. 但这会引发错误

设置:条目,:DevicePreferences :: ConnectHardwareKeyboard ,不存在

任何帮助将不胜感激

解决方案

经历了同样的问题.找到了一个简单的解决方案,在UI测试方案中添加了规定.

首先,这是使用Xcode打开的plist文件的图像.该文件位于〜/Library/Preferences/com.apple.iphonesimulator.plist

现在这是我添加到ui测试方案中的规范.阅读脚本中的注释以获取进一步的解释.

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

工作原理 首先,模拟器被杀死.接下来,默认值"命令将键/值写入模拟器的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆