[android]uiautomator中文輸入解決方案
UiAutomator不支援中文輸入。
通過設定中文輸入法為預設,UiObject.setText("pinyin ") 的方式,可以實現中文輸入,但是隻能輸入一些固定的片語。
github上發現了一個 utf7ime 的好東西,可以實現中文輸入,英文輸入,中英文混合輸入。簡單來說,支援輸入任何unicode編碼的字元。
原理是:UiObject.setText( String) 只能接受ASCII碼,整個過程是輸入的unicode編碼的字串decode成ASCIl碼,setText接受這些ASCll碼再通過utf7ime這個輸入法encode成unicode編碼的字串輸出。
前置條件:手機裝入此輸入法並將之設為預設輸入法
簡單說一說整個過程,
打包下載 https://github.com/sumio/uiautomator-unicode-input-helper
匯入其中的Utf7Ime , 生成apk並安裝設定成預設輸入法
把 helper-library 裡面的Utf7ImeHelper.java匯入自己的公用方法庫,用於把字串decode成ASCII碼
最後生成指令碼是這樣的:
下一步考慮如何將這個功能整合到指令碼錄製工具中去。
文章轉載於:http://testerhome.com/topics/408
有空驗證的同學,驗證完後記得在部落格上留言驗證結果。
通過設定中文輸入法為預設,UiObject.setText("pinyin ") 的方式,可以實現中文輸入,但是隻能輸入一些固定的片語。
github上發現了一個 utf7ime 的好東西,可以實現中文輸入,英文輸入,中英文混合輸入。簡單來說,支援輸入任何unicode編碼的字元。
原理是:UiObject.setText( String) 只能接受ASCII碼,整個過程是輸入的unicode編碼的字串decode成ASCIl碼,setText接受這些ASCll碼再通過utf7ime這個輸入法encode成unicode編碼的字串輸出。
前置條件:手機裝入此輸入法並將之設為預設輸入法
簡單說一說整個過程,
打包下載 https://github.com/sumio/uiautomator-unicode-input-helper
匯入其中的Utf7Ime , 生成apk並安裝設定成預設輸入法
把 helper-library 裡面的Utf7ImeHelper.java匯入自己的公用方法庫,用於把字串decode成ASCII碼
最後生成指令碼是這樣的:
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
import com.sn.test.testUtil.AppAPI;
import com.sn.test.testUtil.Utf7ImeHelper;
public class TestInput extends UiAutomatorTestCase {
private String caseName = this.getClass().getSimpleName();
private String caseDetail = "";
private String description = "";
private boolean result = false;
protected void setUp() throws Exception {
super.setUp();
AppAPI.setUp(caseName);
}
public void testDemo() throws UiObjectNotFoundException, RemoteException {
new UiObject(new UiSelector().className("android.widget.TextView")
.text("資訊")).clickAndWaitForNewWindow();
sleep(1000);
new UiObject(new UiSelector().className("android.widget.RadioButton")
.text("新資訊")).clickAndWaitForNewWindow();
sleep(1000);
new UiObject(new UiSelector().className("android.widget.EditText"))
.setText(Utf7ImeHelper.e("test test yingwen 中文一起輸入"));
sleep(1000);
下一步考慮如何將這個功能整合到指令碼錄製工具中去。
文章轉載於:http://testerhome.com/topics/408
有空驗證的同學,驗證完後記得在部落格上留言驗證結果。
相關文章
- Android輸入鍵盤隱藏解決方案Android
- Android多個EditText輸入效果解決方案Android
- 【Android Studio】解決 Android Studio2.2 無法輸入中文標點符號的問題Android符號
- Unity3D Android鍵盤輸入內容為白色解決方案Unity3DAndroid
- C++ 資料輸入cin (解決CLoin輸入中文程式出錯)C++
- 解決 React 中的 input 輸入框在中文輸入法下的 bugReact
- Linux Ubuntu 20.04 LTS 解決無法輸入中文 輸入法問題LinuxUbuntu
- 解決 Intellij IDEA 中文輸入法不跟隨游標IntelliJIdea
- Android輸入事件詳解Android事件
- 5、中文的輸出(GBK不可對映字元的解決方案)字元
- 解決Ubuntu 18.04中文輸入法的問題Ubuntu
- linux 下 android studio 不能輸入中文記錄LinuxAndroid
- Android測試工具 UIAutomator入門與介紹AndroidUI
- win10系統下中文輸入法無法輸入中文如何解決Win10
- Linux Mint下Qt Creator無法輸入中文解決辦法LinuxQT
- SOLIDWORKS交通運輸解決方案Solid
- Win10電腦搜狗輸入法無法輸入中文及輸入法欄不見了的解決方法Win10
- win10網頁無法輸入中文怎麼解決_win10網頁不能輸入中文怎麼辦Win10網頁
- react輸入框輸入中文bugReact
- Ubuntu18.04中解決emacs無法輸入中文的問題UbuntuMac
- 【slam】解決ubuntu無法透過拼音輸入中文的問題SLAMUbuntu
- 怎麼解決Ubuntu中spyder不能輸入中文的問題阿Ubuntu
- Win10《紀元1800》無法輸入中文如何解決 win10玩紀元1800遊戲不能輸入中文的解決步驟Win10遊戲
- Android uiautomator自動化工具AndroidUI
- win10系統下Cortana無法輸入中文怎麼解決Win10
- MySql中表單輸入資料出現中文亂碼的解決方法MySql
- Android 圖片高斯模糊解決方案Android
- Android Studio 報錯解決方案 一Android
- manjaro中文輸入法JAR
- win10瀏覽器無法使用中文輸入法的解決方法Win10瀏覽器
- 解決CentOS7系統無法使用中文輸入法的問題CentOS
- [linux]解決wayland協議下 google-chrome 無法輸入中文問題Linux協議GoChrome
- [轉]Android Studio匯入工程報錯 Error:Cause: peer not authenticated 解決方案AndroidError
- linux輸入yum後提示: -bash: /usr/bin/yum: No such file or directory的解決方案Linux
- pycharm不能輸入怎麼解決PyCharm
- IDEA控制檯輸出中文亂碼解決方法Idea
- win10 dota不能輸入中文怎麼辦_win10 dota突然打不出中文解決方法Win10
- CentOS 7 輸入中文 & 安裝搜狗輸入法CentOS
- Android7.1.1Toast崩潰解決方案AndroidAST