|
1、启动AS,并创建一个空的android项目;
2、创建成功后,修改build.gradle文件中使项目能依赖Uiautomator类
就在dependencies节点中添加一句
androidTestCompile ‘com.android.support.test.uiautomator:uiautomator-v18:2.1.0’
3、添加后重新Sync Project with Gradle Files
4、当重新Sync成功后,会发现在External Libraries中会添加添加进uiautomator-v18:2.1.0类
5、然后在AndroidTest下创建一个Test类
6、在创建的test类中添加对应的setup、testcase、tearDown方法
对应内容如下
public class Pad_TestWelcome extends UiAutomatorTestCase {
public static String TAG=”qfdapptest”;
private UiDevice device;
@Rule
public ActivityTestRule mActivityRule = new ActivityTestRule<>(
MainActivity.class);
public void setUp() throws Exception {
super.setUp();
device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
System.out.println("setUP --------------------");
}
@Test
public void test_case() throws UiObjectNotFoundException, IOException, InterruptedException {
//在这里添加或调用要执行的测试用例
}
public void tearDown() throws Exception{
super.tearDown();
System.out.println("tearDown --------------------");
}
}
7、编写好脚本后,选中跟test类,右击运行
8、跟着在控制台查看运行结果
|
|