uiautomator2进阶
生活随笔
收集整理的這篇文章主要介紹了
uiautomator2进阶
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
點擊控件的具體位置
d(text="Settings").click(offset=(0.5, 0.5))? ?點擊控件的中間位置
d(text="Settings").click(offset=(0, 0))? 點擊控件的左上方
d(text="Settings").click(offset=(1, 1)) 點擊控件的右下方
拖動控件
d(text="Settings").swipe("right") d(text="Settings").swipe("left", steps=10) d(text="Settings").swipe("up", steps=20) d(text="Settings").swipe("down", steps=20)# 1 steps is about 5ms, so 20 steps is about 0.1s
特定UI對象上的兩點手勢:從邊緣到中心向外,從中心到邊緣
# 從邊緣到中心 d(text="Settings").pinch_in(percent=100, steps=10) # 從中心到邊緣 d(text="Settings").pinch_out()等待特定的界面出現(xiàn)或者消失
# 等待UI出現(xiàn) d(text="Settings").wait(timeout=3.0) # return bool # 等待UI消失 d(text="Settings").wait_gone(timeout=1.0)
對特定的UI對象執(zhí)行Fling(可滾動)默認時間20s
# 向前(默認) d(scrollable=True).fling() # 擲球前水平 d(scrollable=True).fling.horiz.forward() # 垂直向后投擲 d(scrollable=True).fling.vert.backward() # 水平開始 d(scrollable=True).fling.horiz.toBeginning(max_swipes=1000) # 垂直拋向末端 d(scrollable=True).fling.toEnd()
對特定的UI對象執(zhí)行滾動
水平或垂直
向前或向后,或開始或結(jié)束,
# 垂直向前滾動(默認) d(scrollable=True).scroll(steps=10) # 水平向前滾動 d(scrollable=True).scroll.horiz.forward(steps=100) # 垂直向后滾動 d(scrollable=True).scroll.vert.backward() # 水平 d(scrollable=True).scroll.horiz.toBeginning(steps=100, max_swipes=1000) # 垂直滾動到結(jié)尾 d(scrollable=True).scroll.toEnd() # 垂直向前滾動,直到出現(xiàn)特定的UI對象d(scrollable=True).scroll.to(text="Security")
當選擇器找不到匹配項時,uiautomator2將運行所有注冊的觀察程序,條件匹配時單擊目標 d.watcher("AUTO_FC_WHEN_ANR").when(text="ANR").when(text="Wait") \ .click(text="Force Close")
#使用不帶參數(shù)的click
d.watcher("ALERT").when(text="OK").click()
#same as d.watcher("ALERT").when(text="OK").click(text="OK")
#當條件為真時按鍵 d.watcher("AUTO_FC_WHEN_ANR").when(text="ANR").when(text="Wait") \ .press("back", "home")
#檢查指定的觀察程序是否觸發(fā)一個觀察者被觸發(fā),這意味著觀察者已經(jīng)運行并且其所有條件都匹配。 # true in case of the specified watcher triggered, else false
d.watcher("watcher_name").triggered #展示所有watch
d.watchers
#通常可以用來自動點擊權(quán)限確認框,或者自動安裝 d.watcher("OK").when(text="OK").click(text="OK") # enable auto trigger watchers d.watchers.watched = True # disable auto trigger watchers d.watchers.watched = False # get current trigger watchers status assert d.watchers.watched == False
#移除watch # remove all registered watchers d.watchers.remove() # remove the named watcher, same as d.watcher("watcher_name").remove() d.watchers.remove("watcher_name")
全局設(shè)置
#用戶每次點擊后延遲1.5s
d.click_post_delay = 1.5
#設(shè)置默認元素超時時間(s) d.wait_timeout = 30.0 #輸入法 d.set_fastinput_ime(True) # 切換成FastInputIME輸入法 d.send_keys("你好123abcEFG") # adb廣播輸入 d.clear_text() # 清除輸入框所有內(nèi)容(Require android-uiautomator.apk version >= 1.0.7) d.set_fastinput_ime(False) # 切換成正常的輸入法 d.send_action("search") # 模擬輸入法的搜索 ? uiautomation2哈哈哈哈
?
? ? ? ?
轉(zhuǎn)載于:https://www.cnblogs.com/zhujunsheng/p/10452073.html
總結(jié)
以上是生活随笔為你收集整理的uiautomator2进阶的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 农行ETC信用卡多久能办下来?银行审核进
- 下一篇: 原生Js_实现广告弹窗