【移動應(yīng)用開發(fā)技術(shù)】Android4.3引入的UiAutomation新框架官方簡介_第1頁
【移動應(yīng)用開發(fā)技術(shù)】Android4.3引入的UiAutomation新框架官方簡介_第2頁
【移動應(yīng)用開發(fā)技術(shù)】Android4.3引入的UiAutomation新框架官方簡介_第3頁
【移動應(yīng)用開發(fā)技術(shù)】Android4.3引入的UiAutomation新框架官方簡介_第4頁
免費(fèi)預(yù)覽已結(jié)束,剩余1頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

【移動應(yīng)用開發(fā)技術(shù)】Android4.3引入的UiAutomation新框架官方簡介

譯者序:Google在Android4.3發(fā)布時(shí)提供了一套新的UiAutomation框架來支持用戶界面自動化測試,該框架通過運(yùn)用已有的AccessibilityAPIs來模擬用戶跟設(shè)備用戶界面的交互:比如獲取窗口界面控件和注入事件等。如在4.3之前UiAutomator工具是通過InputManager或者更早的WindowManager來注入KeyEvent等,4.3之后用的就是新框架UiAutomation使用的AccessibilityAPIs來注入事件了。ClassOverview/概覽Classforinteractingwiththedevice'sUIbysimulationuseractionsandintrospectionofthescreencontent.ItreliesontheplatformaccessibilityAPIstointrospectthescreenandtoperformsomeactionsontheremoteviewtree.Italsoallowsinjectingofarbitraryrawinputeventssimulatinguserinteractionwithkeyboardsandtouchdevices.OnecanthinkofaUiAutomationasaspecialtypeof

AccessibilityService

whichdoesnotprovidehooksfortheservicelifecycleandexposesotherAPIsthatareusefulforUItestautomation.這是一個(gè)通過模擬用戶操作來與設(shè)備用戶界面交互以及獲取屏幕內(nèi)容的類。它依賴于平臺的輔助功能APIs來在遠(yuǎn)程的控件樹上獲取屏幕內(nèi)容以及執(zhí)行一些操作。同時(shí)它也允許通過注入原生事件(譯者注:指的就是InputEvent.KeyEvent也是繼承于InputEvent的,所以說它是原生事件)來模擬用戶的按鍵和觸屏操作。我們可以認(rèn)為UiAutomation就是一個(gè)特殊類型的AccessibilityService,其既不會為控制服務(wù)的生命周期而提供鉤子函數(shù),也不會暴露任何其他可以直接用于用戶界面測試自動化的APIs.TheAPIsexposedbythisclassarelow-leveltomaximizeflexibilitywhendevelopingUItestautomationtoolsandlibraries.Generally,aUiAutomationclientshouldbeusingahigher-levellibraryorimplementhigh-levelfunctions.Forexample,performingataponthescreenrequiresconstructionandinjectingofatouchdownandupeventswhichhavetobedeliveredtothesystembyacallto

injectInputEvent(InputEvent,boolean).這個(gè)類暴露出來的APIs是很低層的,目的就是為了在開發(fā)用戶界面測試自動化框架和庫時(shí)提供最大的彈性。總的來說,一個(gè)UiAutomation客戶端應(yīng)該使用一些(基于UiAutomation的)更高層次的庫或者實(shí)現(xiàn)更高層次的方法。比如,模擬一個(gè)用戶在屏幕上的點(diǎn)擊事件需要構(gòu)造并注入一個(gè)按下和一個(gè)彈起事件,然后必須調(diào)用UiAutomation的一個(gè)injectInputEvent(InputEvent,boolean)的調(diào)用來發(fā)送給操作系統(tǒng)。TheAPIsexposedbythisclassoperateacrossapplicationsenablingaclienttowriteteststhatcoverusecasesspanningovermultipleapplications.Forexample,goingtothesettingsapplicationtochangeasettingandtheninteractingwithanotherapplicationwhosebehaviordependsonthatsetting.這個(gè)類暴露出來的APIs可以跨應(yīng)用,這樣用戶就可以編寫可以跨越多個(gè)應(yīng)用的測試用例腳本了。比如,打開系統(tǒng)的設(shè)置應(yīng)用去修改一些設(shè)置然后再與另外一個(gè)依賴于該設(shè)置的應(yīng)用進(jìn)行交互(譯者注:這個(gè)在instrumentation這個(gè)框架可以做不到的)。TestingandDebugging(來自android4.3的APIs官方改動文檔)Thenew

UiAutomation

classprovidesAPIsthatallowyoutosimulateuseractionsfortestautomation.Byusingtheplatform's

AccessibilityService

APIs,the

UiAutomation

APIsallowyoutoinspectthescreencontentandinjectarbitrarykeyboardandtouchevents.新的UiAutomation這個(gè)類提供了一系列的APIs來允許你在測試自動化時(shí)模擬用戶的操作。通過封裝使用了平臺上的AccessibilityService

APIs,

UiAutomation

APIs允許你獲取窗口(控件)內(nèi)容并且注入按鍵和觸屏事件。Togetaninstanceof

UiAutomation,call

Instrumentation.getUiAutomation().Inorderforthistowork,youmustsupplythe

-w

optionwiththe

instrument

commandwhenrunningyour

InstrumentationTestCase

from

adbshell.你可以通過調(diào)用Instrumentation.getUiAutomation()來獲得UiAutomation的一個(gè)實(shí)例。為了讓它工作起來,當(dāng)你在adbshell上運(yùn)行你的InstrumentationTestCase的時(shí)候你還需要為instrument命令提供-w這個(gè)選項(xiàng)。Withthe

UiAutomation

instance,youcanexecutearbitraryeventstotestyourappbycallingexecuteAndWaitForEvent(),passingita

Runnable

toperform,atimeoutperiodfortheoperation,andanimplementationofthe

UiAutomation.AccessibilityEventFilter

interface.It'swithinyourUiAutomation.AccessibilityEventFilter

implementationthatyou'llreceiveacallthatallowsyoutofiltertheeventsthatyou'reinterestedinanddeterminethesuccessorfailureofagiventestcase.通過UiAutomation的實(shí)例,你可以調(diào)用其executeAndWaitForEvent()對你的應(yīng)用注入不同的事件來進(jìn)行測試:該函數(shù)會接受一個(gè)可執(zhí)行

Runnable線程對象用來執(zhí)行事件注入操作,一個(gè)操作超時(shí),以及一個(gè)實(shí)現(xiàn)了UiAutomation.AccessibilityEventFilter的類的實(shí)例。正是在這個(gè)UiAutomation.AccessibilityEventFilter實(shí)現(xiàn)類里面你會收到一個(gè)回調(diào)來讓你過濾那些你喜歡的事件并決定你的測試用例是否通過。Toobservealltheeventsduringatest,createanimplementationof

UiAutomation.OnAccessibilityEventListenerandpassitto

setOnAccessibilityEventListener().YourlistenerinterfacethenreceivesacalltoonAccessibilityEvent()

eachtimeaneventoccurs,receivingan

AccessibilityEvent

objectthatdescribestheevent.如果要在測試時(shí)監(jiān)控所有的事件,你需要?jiǎng)?chuàng)建一個(gè)UiAutomation.OnAccessibilityEventListener的實(shí)現(xiàn)類然后把它的實(shí)例傳遞給setOnAccessibilityEventListener()。你的監(jiān)聽接口將會在每次有事件觸發(fā)的時(shí)候接收到一個(gè)發(fā)送給onAccessibilityEvent()的回調(diào),里面的參數(shù)就是一個(gè)描述該事件的AccessibilityEvent

的對象Thereisavarietyofotheroperationsthatthe

UiAutomation

APIsexposeataverylowleveltoencouragethedevelopmentofUItesttoolssuchas

uiautomator.Forinstance,

UiAutomation

canalso:

UiAutomation

APIs還暴露了很多其他的低層次的操作來鼓勵(lì)大家去開發(fā)如uiautomator這樣的用戶界面測試工具。比如UiAutomation還可以做以下事情:AndmostimportantlyforUItesttools,the

UiAutomation

APIsworkacrossapplicationboundaries,unlikethoseinInstrumentation.最為用戶界面自動化測試工具,最重要的一點(diǎn)是,UiAutomation

APIs可以跨應(yīng)用工作,而不像Instrumenta

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論