UIAutomator输入中文
之前一直是英文的測試環(huán)境,包括手機也是英文的,app也是英文的,涉及不到中文輸入法的東西。但現(xiàn)在在寫中文的app,所以需要輸入中文??吹骄W(wǎng)上的解決辦法如下:
下載https://github.com/sumio/uiautomator-unicode-input-helper源碼
Install Utf7Ime and change the default IME
- Import?Utf7Ime/?directory into your Eclipse workspace. You can import by?File -> Import... -> Existing Android Code Into Workspace.
- Build?Utf7Ime?project and install it on your Android-powered device (or emulator) for UI testing.
- Launch?Settings?App in the device.
- Open?Language & input.
- Switch on the?UTF7 IME for UI Testing?checkbox belonging to?KEYBOARD & INPUT METHODS?category.
- Tap?Default?belonging to?KEYBOARD & INPUT METHODS?category.
- Change the default IME to Utf7Ime by selecting?UTF7 IME for UI Testing.
Copy the helper library to your Uiautomator project
Copy?helper-library/src/*?to?<your uiaotomator project>/src/.
大意是下載之后將Utf7Ime工程導入到eclipse中,之后build android工程,生成Utf7Ime.apk,安裝到測試機中,并把手機語言設置成為“UTF7 IME for UI Testing”;
把helper-library/src/*下的源碼復制到你的UIAutomator測試工程的/src/里。
?
我這邊也是按照這個來的,只是把Utf7ImeHelper.e()封裝到了commonHelper.java文件中,之后調(diào)用:
然后就可以輸入中文了。
但是這里有個問題:輸入中文之后,點擊enter鍵,執(zhí)行搜索,但在當前的UTF7 IME for UI Testing輸入法下是沒有鍵盤的出現(xiàn)的,所以無法點擊enter鍵。
為了解決這個問題,我想到的解決方案是:想輸入中文時,就把輸入法改成UTF7 IME for UI Testing,輸入完之后,再把輸入法修改回來,這樣鍵盤又彈出來了,之后再點擊enter鍵,這樣就能實現(xiàn)搜索。
那就有另一個問題,如何實現(xiàn)快速切換輸入法:http://www.cnblogs.com/yajing-zh/p/5125317.html
?
轉(zhuǎn)載于:https://www.cnblogs.com/yajing-zh/p/5125387.html
總結(jié)
以上是生活随笔為你收集整理的UIAutomator输入中文的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数学概念——J - 数论,质因数分解
- 下一篇: Android无法生成R文件的终极解决办