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码
最后生成脚本是这样的:
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 UIAutomator自动化测试代码。相关博客地址https://blog.csdn.net/qq752387519/article/details/80007002
主要分析 Android uiautomator常用的api,并结合实例和具体介绍
Uiautomator Unicode Input Helper使您能够使用 Android 输入任何 Unicode(包括非 ASCII)字符。 Uiautomator 有 API 来设置可编辑字段中的文本。 如果文本仅包含 ASCII 字符,但不能输入任何非 ASCII 字符(例如...
UiAutomator2,Android Studio工程,支持中文输入 UiAutomator 谷歌推出的,用于UI自动化测试的工具 Android 4.1及以上,不支持Hybird App、WebApp 基于Java,测试代码结构简单、编写容易 直接在手机上运行 配合ui...
报告简介及查看.mp4
本文档是Android自动化工具uiautomator的源代码。 仅供个人使用。
uiautomator2,android uiautomator2 python包装器.zip
android uiautomator 源码
本文就介绍了4中Android屏幕自适应解决方案。 一、细说layout_weight 目前最为推荐的Android多屏幕自适应解决方案。 该属性的作用是决定控件在其父布局中的显示权重,一般用于线性布局中。其值越小,则对应的...
uiautomator在android api21以下如何启动apk,进行自动化测试
android-uiautomator-jsonrpcserver 最新代码android-uiautomator-jsonrpcserver 最新代码android-uiautomator-jsonrpcserver 最新代码android-uiautomator-jsonrpcserver 最新代码android-uiautomator-...
Android:最全面解析Android消息推送解决方案.docx
Configurator类介绍与API解说.mp4
Android限制只能输入中文的EditText,对输入的内容进行监听拦截。
This module is a Python wrapper of Android uiautomator testing framework. It works on Android 4.1 simply with Android device attached via adb, no need to install anything on Android device. from ...
uiautomator源码, Android UI 自动化测试工具源码。
UiAutomator 快速调试的工具包,使用时请参考UiAutomator Android 的自动测试框架(UiAutomator 快速调试)
基于UiAutomator框架,自动模拟用户手势操作,类似于触摸精灵,按键精灵的app。
UiAutomatorDemo for android