您好,登錄后才能下訂單哦!
譯者序:Google在Android 4.3發布時提供了一套新的UiAutomation框架來支持用戶界面自動化測試,該框架通過運用已有的Accessibility APIs來模擬用戶跟設備用戶界面的交互:比如獲取窗口界面控件和注入事件等。如在4.3之前UiAutomator工具是通過InputManager或者更早的WindowManager來注入KeyEvent等,4.3之后用的就是新框架UiAutomation使用的Accessibility APIs來注入事件了。
Class for interacting with the device's UI by simulation user actions and introspection of the screen content. It relies on the platform accessibility APIs to introspect the screen and to perform some actions on the remote view tree. It also allows injecting of arbitrary raw input events simulating user interaction with keyboards and touch devices. One can think of a UiAutomation as a special type of AccessibilityService
which does not provide hooks for the service life cycle and exposes other APIs that are useful for UI test automation.
這是一個通過模擬用戶操作來與設備用戶界面交互以及獲取屏幕內容的類。它依賴于平臺的輔助功能APIs來在遠程的控件樹上獲取屏幕內容以及執行一些操作。同時它也允許通過注入原生事件(譯者注:指的就是InputEvent. KeyEvent也是繼承于InputEvent的,所以說它是原生事件)來模擬用戶的按鍵和觸屏操作。我們可以認為UiAutomation就是一個特殊類型的AccessibilityService,其既不會為控制服務的生命周期而提供鉤子函數,也不會暴露任何其他可以直接用于用戶界面測試自動化的APIs.
The APIs exposed by this class are low-level to maximize flexibility when developing UI test automation tools and libraries. Generally, a UiAutomation client should be using a higher-level library or implement high-level functions. For example, performing a tap on the screen requires construction and injecting of a touch down and up events which have to be delivered to the system by a call to injectInputEvent(InputEvent, boolean)
.
這個類暴露出來的APIs是很低層的,目的就是為了在開發用戶界面測試自動化框架和庫時提供最大的彈性。總的來說,一個UiAutomation客戶端應該使用一些(基于UiAutomation的)更高層次的庫或者實現更高層次的方法。比如,模擬一個用戶在屏幕上的點擊事件需要構造并注入一個按下和一個彈起事件,然后必須調用UiAutomation的一個injectInputEvent(InputEvent, boolean)的調用來發送給操作系統。
The APIs exposed by this class operate across applications enabling a client to write tests that cover use cases spanning over multiple applications. For example, going to the settings application to change a setting and then interacting with another application whose behavior depends on that setting.
這個類暴露出來的APIs可以跨應用,這樣用戶就可以編寫可以跨越多個應用的測試用例腳本了。比如,打開系統的設置應用去修改一些設置然后再與另外一個依賴于該設置的應用進行交互(譯者注:這個在instrumentation這個框架可以做不到的)。
Testing and Debugging(來自android 4.3的APIs官方改動文檔)
The new UiAutomation
class provides APIs that allow you to simulate user actions for test automation. By using the platform's AccessibilityService
APIs, the UiAutomation
APIs allow you to inspect the screen content and inject arbitrary keyboard and touch events.
新的UiAutomation這個類提供了一系列的APIs來允許你在測試自動化時模擬用戶的操作。通過封裝使用了平臺上的AccessibilityService APIs, UiAutomation
APIs允許你獲取窗口(控件)內容并且注入按鍵和觸屏事件。
To get an instance of UiAutomation
, call Instrumentation.getUiAutomation()
. In order for this to work, you must supply the -w
option with the instrument
command when running your InstrumentationTestCase
from adb shell
.
你可以通過調用Instrumentation.getUiAutomation()來獲得UiAutomation的一個實例。為了讓它工作起來,當你在adb shell上運行你的InstrumentationTestCase的時候你還需要為instrument命令提供-w這個選項。
With the UiAutomation
instance, you can execute arbitrary events to test your app by callingexecuteAndWaitForEvent()
, passing it a Runnable
to perform, a timeout period for the operation, and an implementation of the UiAutomation.AccessibilityEventFilter
interface. It's within yourUiAutomation.AccessibilityEventFilter
implementation that you'll receive a call that allows you to filter the events that you're interested in and determine the success or failure of a given test case.
通過UiAutomation的實例,你可以調用其executeAndWaitForEvent()對你的應用注入不同的事件來進行測試:該函數會接受一個可執行 Runnable線程對象用來執行事件注入操作,一個操作超時,以及一個實現了UiAutomation.AccessibilityEventFilter的類的實例。正是在這個UiAutomation.AccessibilityEventFilter實現類里面你會收到一個回調來讓你過濾那些你喜歡的事件并決定你的測試用例是否通過。
To observe all the events during a test, create an implementation of UiAutomation.OnAccessibilityEventListener
and pass it to setOnAccessibilityEventListener()
. Your listener interface then receives a call toonAccessibilityEvent()
each time an event occurs, receiving an AccessibilityEvent
object that describes the event.
如果要在測試時監控所有的事件,你需要創建一個UiAutomation.OnAccessibilityEventListener的實現類然后把它的實例傳遞給setOnAccessibilityEventListener()。你的監聽接口將會在每次有事件觸發的時候接收到一個發送給onAccessibilityEvent()的回調,里面的參數就是一個描述該事件的AccessibilityEvent
的對象
There is a variety of other operations that the UiAutomation
APIs expose at a very low level to encourage the development of UI test tools such as uiautomator. For instance, UiAutomation
can also:
UiAutomation
APIs還暴露了很多其他的低層次的操作來鼓勵大家去開發如uiautomator這樣的用戶界面測試工具。比如UiAutomation還可以做以下事情:
And most importantly for UI test tools, the UiAutomation
APIs work across application boundaries, unlike those inInstrumentation
.
最為用戶界面自動化測試工具,最重要的一點是,UiAutomation
APIs 可以跨應用工作,而不像Instrumentation提供了的那些APIs.
作者 | 自主博客 | 微信 | CSDN |
天地會珠海分舵 | http://techgogogo.com | 服務號:TechGoGoGo 掃描碼:
| 向AI問一下細節 推薦閱讀:
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。 猜你喜歡最新資訊相關推薦相關標簽AI
助 手
高雄县|
吕梁市|
陈巴尔虎旗|
敦煌市|
故城县|
昌宁县|
金沙县|
华宁县|
泸溪县|
吉安市|
东光县|
洮南市|
阳山县|
杨浦区|
琼结县|
泰来县|
金川县|
阜城县|
偃师市|
革吉县|
沂水县|
伊吾县|
庄河市|
乳山市|
青川县|
灵台县|
台南市|
杭锦旗|
阿拉善右旗|
四会市|
常德市|
钦州市|
遂溪县|
宁波市|
霸州市|
乐东|
博乐市|
禄丰县|
岑巩县|
自治县|
屏边|
|