uiautomator2.0框架

1.

 

Uiautomator1.0

Uiautomator2.0

date

2012

2015

super class

UiAutomatorTestCase

InstrumentationTestCase

language

java

java

executable file

jar

APK

API-level

16(4.1)+

18(4.3)+

permission

-

less

context

no

yes

extends

Junit3 需要继承UiAutomatorTestCase

Junit4 测试类不需要继承父类

2.

Linux 下Set up UI Automator2.0

打开android studio,新建工程  File—》new—》new project,选择最小的sdk为19,选择【Blank Activity】,下一步-完成;

3.

修改build.gradle(Module:app)文件

android{}中增加

packagingOptions {

        exclude 'LICENSE.txt'

}

defaultConfig {

        multiDexEnabled true

}

dependencies{}中增加

androidTestCompile 'com.android.support.test:testing-support-lib:0.1'

androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.0.0'     /v18:2.1.1

4.

app-java-..[AndroidTest]中创建类,编写脚本,点击un 运行脚本

                                                          

5.

脱机运行:

uiautomator1.0

.adb push E:eclipse2workspace est-miuiinuitestpowerconsume.jar /data/local/tmp

adb shell uiautomator runtest uitestpowerconsume.jar --nohup -c com.miui.sec.Test_PowerConsume#testPowerConsume

Uiautomator2.0:

方法1.

使用这个nohup  这个参数时,会报错是: nohup: /nohup.out: Read-only file system

所以我使用重新写了个路径    eg: /data/nohup.out

但是是先进到shell中  再执行

nohup am instrument -w -r -e debug false -e class com.demo.mi.myapplication.Demo com.demo.mi.myapplication.test/android.support.test.runner.AndroidJUnitRunner > /data/nohup.out

方法2.

在末尾加上&  也可以实现

先进到shell中  再执行

nohup am instrument -w -r -e debug false -e class com.demo.mi.myapplication.Demo com.demo.mi.myapplication.test/android.support.test.runner.AndroidJUnitRunner&

UIAUTOMATOR 2.0的教程http://blog.csdn.net/java18/article/details/53535928

原文地址:https://www.cnblogs.com/yyh8/p/6902942.html