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:\eclipse2\workspace\test-miui\bin\uitestpowerconsume.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

