uiautomator中文输入解决方案
2015-11-09 15:07
274 查看
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码
最后生成脚本是这样的:
package com.meizu.test; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import android.view.KeyEvent; import com.android.uiautomator.core.UiDevice; import com.android.uiautomator.core.UiObject; import com.android.uiautomator.core.UiObjectNotFoundException; import com.android.uiautomator.core.UiScrollable; import com.android.uiautomator.core.UiSelector; import com.android.uiautomator.core.UiWatcher; import com.android.uiautomator.testrunner.UiAutomatorTestCase; import com.beetstra.jutf7.Utf7ImeHelper; /** * android list * 创建build文件 android create uitest-project -n RunnerDemo -t 2 -p E:\android_workspace\UiautomatorTest * 编译生成jar 右击build.xml运行 Ant Build * 导入jar文件adb push E:\android_workspace\UiautomatorTest\bin\RunnerDemo.jar /sdcard/ * 运行jar文件 adb shell uiautomator runtest <jar文件名> -c <工程中的类名,包含包名> * adb shell uiautomator runtest /sdcard/filemanager.jar -c com.meizu.filemanager.test.FilemanagerSanityTestCase#test123 * * * id=UiAutomatorTestRunner * test=testCreateContact * class=com.meizu.test.TestCase * * [ro.build.inside.id]: [5.1-20150708021621]这个是prd版本是没有权限写的。的如果数字后面有个-i的话就是user版本的。 * * 1、研究大小写 * 2、研究utf-7 * * 注意:robotium框架里:exec()方法里面参数不能加adb shell 否则报错IOExpetion * * //如何匹配图标 * * 1、在github上下载了utf7ime输入法的源码,编译了输入法apk到手机里,把utf7代码包放到项目中,调用里面的utf7imeHelper类里面的e()方法,它的原理是将Unicode码破译成ASCII码后传给UiObject.setText()方法,再由手机里的utf7ime将ASCII编译成Unicode码。 * 2、在统计文件夹下内容个数的时候,多了的.nomedia文件是为了跳过开机媒体扫描加快开机速度减少系统开销的,它不在目录下显示,所以在统计个数时判断一下忽略掉它。 * 3、进行swipe滑动的时候不能取这三个边界值(0,width,heigh),否则滑动无效。可以取(50,width-50,width/2+200,width/2-200)。速度可为10。 * * 2015年7月9日 * @author niming */ public class TestCase extends UiAutomatorTestCase { private UiDevice uiDevice; private int width; private int height; @Override protected void setUp() throws Exception { super.setUp(); uiDevice = getUiDevice(); width = uiDevice.getDisplayWidth(); height = uiDevice.getDisplayHeight(); uiDevice.pressHome(); } @Override protected void runTest() throws Throwable { try { super.runTest(); System.out.println("true\ntrue\ntrue"); } catch (Throwable e) { System.out.println("false\nfalse\nfalse"); throw new Throwable(e); } } @Override protected void tearDown() throws Exception { super.tearDown(); }
new UiObject(new UiSelector().text(Utf7ImeHelper.e("设置"))).click();下一步考虑如何将这个功能集成到脚本录制工具中去。
文章转载于:http://testerhome.com/topics/408
相关文章推荐
- UITableView左滑出现多个按钮
- UITableView 类似通讯录的索引
- 禁止uiscrollview垂直方向滚动,只允许水平方向滚动;或只允许垂直方向滚动
- UIWindow的简单实用(二)
- 复古篇:重现iOS6UITableView的Group风格
- iOS-UIViewController创建的几种方法和UIWindow的介绍
- iOS-UIViewController创建的几种方法和UIWindow的介绍
- UIView的简单实用
- Android开发之利用Fragment建立动态UI
- UISegmentedControl
- 为什么在Pool中传递Queue对象无法运行
- UIMenuController的使用,对UILabel拷贝以及定制菜单 .posted on 2013-03-18 16:20
- UITableView代理方法不执行的原因
- iOS开发UI篇—CAlayer(自定义layer)
- UITableView删除多行
- MIUI 6 沉浸式状态栏调用方法
- UIlabel 属性text
- 让你一看就会的UI知识一
- mybastis中的queryOne方法始终差不多值
- Android:BLE(Bluetooth Low Energy)开发