自动化测试——切换Android输入法

在写测试脚本时,遇到这样一个问题,点击一个输入框,可以输入文字,也可以点击下面的弹出的面板进行录音,如下图所示页面

自动化测试——切换Android输入法_第1张图片

但使用Appium进行自动化测试时,我们一般会将 Capabilities 设置中的 unicodeKeyboard() 设置成true 【unicodeKeyboard(true)】,这个选项的意思是,使用unicode编码的键盘,这样设置后,手机的输入法就会变成 Appium Android Input Manager for Unicode,这种输入法是没有软键盘页面的。这就导致不能继续下面的脚本书写。

所以,遇到这种情况时,我们可以通过执行adb 切换输入的命令,改变当前的输入法,之后,再将其修改回来。

appium-java-client 可以这样写:

List arguments=Arrays.asList("set", "com.android.inputmethod.latin/.LatinIME");

Map command = ImmutableMap.of("command", "ime", "args", arguments);

driver.executeScript("mobile:shell", command);

 

Android键盘(AOSP) ~ 系统默认(拉丁) -----com.android.inputmethod.latin/.LatinIME 

appium设置的unicodeKeyboard  ------io.appium.android.ime/.UnicodeIME

 

参考:https://testerhome.com/topics/2403

查询已安装输入法adb shell ime list -a
切换输入法adb shell ime set com.android.inputmethod.pinyin/.PinyinIME
隐藏键盘 hidekeyboard()
再切回appium输入法 adb shell ime set io.appium.android.ime/.UnicodeIME

 

 

你可能感兴趣的:(自动化测试——切换Android输入法)