【uiautomator】UiDevice
UiDevice
類描述:
UiDevice用于訪問有關設備的狀態信息,你可以使用該類來模擬設備上的用戶行為,例如d-pad鍵操作或者Home鍵和menu鍵
方法描述:
按鍵使用
click(int x,int y):boolean – UiDevice
//單擊用戶指定的坐標
pressBack():boolean-UiDevice
//模擬Back鍵
pressDelete():boolean-UiDevice
//模擬Delete鍵
pressDpadCenter():boolean-UiDevice
//模擬Center鍵
pressDpadDown():boolean-UiDevice
//模擬Down鍵
pressDpadLeft():boolean-UiDevice
//模擬左鍵
pressDpadRight():boolean-UiDevice
//模擬右鍵
pressDpadUp():boolean-UiDevice
//模擬UP鍵
pressEnter():boolean-UiDevice
//模擬Enter鍵
pressHome():boolean-UiDevice
//模擬HOME鍵
pressKeyCode(int keyCode):boolean-UiDevice
//使用keyCode模擬鍵盤按鍵
pressKeyCode(int keyCode,int metaState):boolean-UiDevice
//模擬按鍵代碼,metaState=shift=1
pressMenu():boolean-UiDevice
//MENU鍵
pressRecentApps():boolean-UiDevice
//按最近應用程序按鍵
pressSearch():boolean-UiDevice
//模擬搜索鍵
?
拖拽與滑動
drag(int startX,int startY,int endX,int endY,int steps):boolean – UiDevice
//將一個坐標拖拽另一個坐標
swipe(Point[] segments,int segmentSteps):boolean-UiDevice
//點陣列中滑動,5ms為一步
//segments:Point[]點陣列,可多個點;segmentSteps:滑動步長
swipe (int startX,int startY,int endX,int endY,int steps):boolean – UiDevice
//滑動屏幕
?
旋轉屏幕
freezeRotation():void – UiDevice
//禁用傳感器和凍結當前旋轉狀態的設備旋轉
getDisplayRotation():int – UiDevice
//返回當前的旋轉狀態,0,1,2,3分表代表0,90,180,270
serOrientationLeft():void-UiDevice
//禁用傳感器,模擬屏幕設備左轉,并且固定位置
setOrientationNatural():void-UiDevice
//禁用傳感器,模擬屏幕轉到其自然默認方向,并固定位置
setOrientationRight():void-UiDevice
//固定傳感器,模擬屏幕設備右轉,并且固定位置
unfreezeRotation():void-UiDevice
//重新啟用傳感器和允許物理旋轉
isNaturalOrientation(): boolean-UiDevice
//檢查裝置是否在自然旋轉豎屏位置上
?
滅屏與喚醒屏幕
wakeup():void-UiDevice
//該方法模擬按電源鍵,如果屏幕已喚醒則無任何作用
isScreenOn():boolean-UiDevice
//檢查屏幕是否喚醒
sleep():void-UiDevice
//鎖屏(若屏幕關閉則無作用)?
?
截圖與等待空閑
takeScreenshot(File storePath):boolean– UiDevice
//將當前窗口截屏并存儲為png默認1.0f的規模(原尺寸)和90%的質量,storePath為文件路徑
takeScreenshot(File storePath,float scale,int quality):boolean– UiDevice
//將當前窗截圖為png格式圖片,可自定義縮放比例和質量
//scale:縮放比例,1.0為原圖;quality:圖片壓縮質量,范圍1-100
wait():void-Object
//一直處于睡眠狀態,直到調用notify或者notifyAll
notify():void-Object
//喚醒正在等待該對象的線程
notifyAll():void-Object
//喚起所有正在等待該對象的線程
wait(long timeout):void-Object
//等待**毫秒被喚醒
wait(long timeout,int nanos):void-Object
//等待**毫秒**納秒結束時被喚醒
waitForIdle():void-UiDevice
//等待當前應用程序處于空閑狀態,默認10S
waitForIdle(long timeout):void-UiDevice
//自定義超時等待當前窗口處于空閑狀態
waitForWindowUpdate(String packageName,long timeout):boolean-UiDevice
//等待窗口內容更新的發生
?
獲取包名、設備名
getCurrentPackageName():String – UiDevice
//獲得當前包名:檢索最新的可訪問性事件的包名
getProductName():String – UiDevice
//獲得產品設備名
?
開啟通知欄,打開快速設置
openNotification():boolean-UiDevice
//打開通知欄
openQuickSettinghs():boolean-UiDevice
//打開快速設置
?
獲取布局文件
getDisplayHeight():int – UiDevice
//獲取顯示高度,以像素為單位
getDisplaySizeDp():Point – UiDevice
//返回顯示尺寸(以dp為單位),返回的尺寸適應每個屏幕的旋轉
getDisplayWidth():int – UiDevice
//獲得顯示寬度,以像素為單位
dumpWindowHierachy(String fileName):void – UiDevice
//幫助方法,用于調試轉儲當前窗口的布局層次,文件保存于/data/local/tmp
setCompressedLayoutHeirarchy(boolean compressed):void-UiDevice
//啟用或禁用布局層次壓縮?
?
監聽器
registerWatcher(String name,UiWatcher watcher):void-UiDevice
//注冊UIWatcher并自動運行,當測試框架無法找到一個匹配時使用UISelector
removeWatcher(String name):void-UiDevice
//移除之前注冊的UIWatcher
resetWatcherTriggers():void-UiDevice
//重置已經觸發的UIWatcher
runWatcher():void-UiDevice
//強制運行所有的UIWatcher.
hasAnyWatcherTriggered():boolean-UiDevice
//檢查是否有UIWatcher觸發
hasWatcherTriggered(String watcherName):boolean-UiDevice
//檢查某個特定的監聽器是否觸發
?
其它
clearLastTraversedText():void – UiDevice
//遍歷從過去的UI事件中,清除文本(上一次的輸入)
getCurrentActivityName():String – UiDevice
//此方法過時,返回結果認為不可靠
getLastTraversedText():String – UiDevice
//檢索收到的最后一次遍歷事件的文本
getInstance():Uidevice-UiDevice
//檢索單個UIdevice實例
轉載于:https://www.cnblogs.com/wonderful0714/p/4580029.html
總結
以上是生活随笔為你收集整理的【uiautomator】UiDevice的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【.NET基础】--委托、事件、线程(2
- 下一篇: 数据结构之树和二叉树的应用:二叉排序树(