环境搭建:
1.配置java环境
2.配置sdk环境
3.配置ant环境
4.准备eclipse
常用命令:
1.当前链接设备: adb devices
2.查看adb服务所需端口:adb nodaemon server
3.查看某端口情况:netstat -ano | findstr “5037”
UiAutomator注意点:
1.新建项目从sdk - platforms中倒入“android.jar” 和 “uiautomator.jar”包
2.使用Junit执行
3.每个TestCase命名以test开始:
package com.ln.test; ----------------自己命名包,方便后面调用。
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
public class AutoTestDemo extends UiAutomatorTestCase {
public void testnewTestCase() throws UiObjectNotFoundException{ ----------------每条测试用例以test开头
UiObject username = new UiObject(new UiSelector().resourceId("com.insthub.ezudao:id/signin_mobile_phone"));
username.setText("13260227650");
UiObject pwd = new UiObject(
new UiSelector().resourceId("com.insthub.ezudao:id/signin_password"));
pwd.setText("123456");
UiObject submit = new UiObject(
new UiSelector().resourceId("com.insthub.ezudao:id/signin_signin"));
submit.click();
}
}
对象值使用sdk-tools中的uiautomatorviewer查看。
4.生成 build文件:android create uitest-project -n <name> -t <android-sdk-ID> -p <path>
name:build文件中的name,即生成的jar的name。
android-sdk-id:使用 android list 查看当前id
path:eclipse的workspace目录
5.修改build.xml,将default中的help改为build。
6.生成jar包:ant -buildfile "path"
path:同上
7.将jar包push到设备中:adb push "path\bin\Demo.jar" /data/local/tmp/
path :同上
8.执行测试用例:adb shell uiautomator runtest Demo.jar --nohup -c com.hj.autotest.UiAutomatorTestCase #testnewTestCase ------------一次只能执行一条