Uiautomator 2.0 VS 1.0
簡介:
google早已推出了uiautomator2.0,但是1.0仍然能用,最近由於許多控制元件不能識別,所以嘗試了在2.0上有沒有
這種問題存在。驚奇的發現2.0功能實在比1.0強大很多,所以我們也應該適時改變,去擁抱變化。
WHAT'S NEW IN UIAUTOMATOR 2.0
Most Importantly,Uiautomator is now based on android instrumentation
Instrumentation終於把Uiautomator納入了他的麾下
Google提供的Android Testing Support Library變化挺多的,比如全面擁抱Junit4.0,推薦使用AndroidJunit
Runner,然後使用Android Studio IDE等等。反正不僅在開發端,在測試端,Google也在做一些標準和統一,然後
讓我們忘記之前的MonkeyRunner,Instrumentation
只剩下:
AndroidJunitRunner : Junit4 compatible test runner for android
Espresso: UI Testing framework,suitable for functional UI testing within an app
Uiautomator: UI Testing framework,suitable for cross-app functional UI testing across
system and installed apps
UiAutomator2改進
1. 基於 Instrumentation,可以獲取應用Context,使用 Android服務及介面 2. 基於 Junit4,測試用例無需繼承於任何父類,方法名不限,使用註解 Annotation進行 3. UI執行效率比 1.0 快,測試執行可使用AndroidJunit 方式及gradle 方式4. API 更新,新增UiObject2、Until、By、BySelector等:APIFor UI Automator
5. Log 輸出變更,以往使用System.out.print輸出流回顯至執行端,2.0 輸出至Logcat