使用AndroidStudio執行UI Automator 自動化測試版本問題
阿新 • • 發佈:2019-01-28
摘要
最近在研究UiAutomator自動化測試問題,寫好之後卻報了下面這樣一個問題:
網上看到UIAutomator 2.0版本,並且貌似使用的框架都改變了,所以今天就抽空試了下
We’re pleased to announce the release of UIAutomator 2.0! This version is a significant update from the previous release. Most importantly, UI Automator is now based on Android Instrumentation and you can build and run tests with the ‘./gradlew connectedCheck’ command.
大體的意思就是UIAutomator2.0基於的框架改成了android的instrumentatioin的框架。並且可以通過gradle進行配置了,雖然說實話不太清楚為什麼要將UiAutomator的框架改成instrumentation,但是我們先試試大概答題的環境出來吧。
下來我們就來試試通過Android Studio 來進行UiAutomator的配置吧
UiAutomator2.0的jar包並不是在以前SDK/platforms/android-19/下。現在我們要這麼做
- 通過Android SDK Manager中的 Android Support Repository 項進行安裝
- 下載下來的jar包的路徑為/extras/android/m2repository
- 新建一個android專案,編寫一個簡單的應用
-
在build.gradle中配置依賴項:
dependencies { androidTestCompile 'com.android.support.test:runner:0.3' // Set this dependency to use JUnit 4 rules androidTestCompile 'com.android.support.test:rules:0.3' // Set this dependency to build and run Espresso tests androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
設定AndroidJunitRunner為預設的testInstrumentationRunner
android { defaultConfig { testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" }
}
以上版本問題是解決了,但是jar包的問題還被困擾,有路過的大神望指導一下。