UiAutomator解决中文输入法

一、安装输入法:
1,去utf7ime的 github上把整个项目给下载下来,地址:https://github.com/sumio/uiautomator-unicode-input-helper
点击"Download ZIP"按钮进行 打包下载
2,下载完成 以后解压到本地磁盘的任意位置比如C:\uiautomator-unicode-input-helper-master
3,打开Eclipse(安装了adt,并且配置好sdk home in eclispe不然不能打包)
4,点击File->Import ->Existing Android Code Into Workspace->Next->点击Browser 选择uiautomator-unicode-input-helper-master\Utf7Ime文件夹>点击Done,这个提示发现不了project,请从别的android项目中复制根目录下的配置文件过来就ok了(配置文件.classpath .project proguard.cfg project.properties)
5,导入成功后,安装IME(input method Editor)到手机中;
6,设置-语言及输入法-在设置里面将本机的默认输入法设置成:UTF7 IME for UI Testing,同时取消第三方的输入法(如果你安装了);

二、在测试工程中加入对应的代码
1.将uiautomator-unicode-input-helper-master\helper-library  目录下的src拷贝到测试项目中
2.可使用sample中代码做测试,测试成功,如下:
package logtest;

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.testrunner.UiAutomatorTestCase;

public class UiAutomatorInputStreamTest extends UiAutomatorTestCase {

public void testDemo(){
this.getUiDevice().pressHome();
UiScrollable s = new UiScrollable(new UiSelector().scrollable(true));
s.setAsHorizontalList();
try {
s.scrollForward();
UiObject uo = new UiObject(new UiSelector().text("主题中心"));
uo.clickAndWaitForNewWindow();
} catch (UiObjectNotFoundException e) {
e.printStackTrace();
}
}
}

猜你喜欢

转载自ilovejoe.iteye.com/blog/2100185
今日推荐