是否有可能“切换软件键盘"?通过UI测试中的代码? [英] Is it possible to "toggle software keyboard" via the code in UI test?

查看:50
本文介绍了是否有可能“切换软件键盘"?通过UI测试中的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有UI测试,用于测试登录功能(并使用它来测试其他内容),但是有时当焦点从一个字段更改为另一个字段时-键盘隐藏了,尽管光标在该字段中闪烁,但我得到了错误在field.typeText-no focused fields to fill上.

I have UI tests which testing login functionality (and uses it to test other stuff), but sometimes when focus is changed from one field to another - the keyboard hides, and although the cursor is blinking in the field, I getting error on field.typeText - no focused fields to fill.

我以某种方式意识到,单击Hardware -> Keyboard -> toggle software keyboard可使键盘保留在屏幕上,因此测试效果很好.但是我需要使其在任何测试设备,任何开发人员机器上都可以工作,因此我想以编程方式设置该选项,而不会烦恼该项目的自述文件中的如果测试失败,请转至……并手动设置……".

Somehow I realized, that clicking on a Hardware -> Keyboard -> toggle software keyboard makes keyboard to persist on the screen, so test is works well. But I need to make it working on any testing device, on any developer machine, so I want to set this option programmatically without annoying "if test fails, go to … and set … by hand" in readme of the project.

有可能吗?

推荐答案

模拟器的.plist文件已更改,以增加对多个模拟器的支持.现在,ConnectHardwareKeyboard布尔值嵌套在设备的UDID下.幸运的是,该UDID也存储在plist文件中.您可以在UITest目标的构建阶段下使用运行脚本"添加此代码.

The simulator's .plist file changed to add support for multiple simulators. The ConnectHardwareKeyboard boolean is now nested underneath the device's UDID. Luckily this UDID is also stored in the plist file. You can add this code using 'run script' under your UITest target's build phases.

Xcode 9答案:

Xcode 9 answer:

#grab the UDID from the plist
UDID=$(defaults read com.apple.iphonesimulator CurrentDeviceUDID)

#overwrite the existing value with false
#OR if the plist doesn't have that value add it in
/usr/libexec/PlistBuddy -c "Set :DevicePreferences:$UDID:ConnectHardwareKeyboard 
false" ~/Library/Preferences/com.apple.iphonesimulator.plist 
|| 
/usr/libexec/PlistBuddy -c  "Add :DevicePreferences:$UDID:ConnectHardwareKeyboard
bool false" ~/Library/Preferences/com.apple.iphonesimulator.plist

或者您可以使用此其他代码来影响所有模拟器:

Or you can use this other code to affect all simulators:

/usr/libexec/PlistBuddy -c "Print :DevicePreferences" ~/Library/Preferences/com.apple.iphonesimulator.plist | perl -lne 'print $1 if /^    (\S*) =/' | while read -r a; do /usr/libexec/PlistBuddy -c "Set :DevicePreferences:$a:ConnectHardwareKeyboard
false" ~/Library/Preferences/com.apple.iphonesimulator.plist || /usr/libexec/PlistBuddy -c  "Add :DevicePreferences:$a:ConnectHardwareKeyboard
bool false" ~/Library/Preferences/com.apple.iphonesimulator.plist; done

这篇关于是否有可能“切换软件键盘"?通过UI测试中的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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