最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解python uiautomator2 watcher的使用方法

 更新時(shí)間:2019年09月09日 16:15:07   作者:aziji  
這篇文章主要介紹了python uiautomator2 watcher的使用方法,該方是基于uiautomator2如下版本進(jìn)行驗(yàn)證,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下

該方是基于uiautomator2如下版本進(jìn)行驗(yàn)證的:

PS C:\windows\system32> pip show uiautomator2
Name: uiautomator2
Version: 1.2.2
Summary: Python Wrapper for Android UiAutomator2 test tool
Home-page: https://github.com/codeskyblue/uiautomator2
Author: codeskyblue
Author-email: codeskyblue@gmail.com
License: MIT
Location: c:\program files\python36\lib\site-packages
Requires: six, progress, whichcraft, logzero, lxml, adbutils, retry, Pillow, requests, humanize
Required-by: weditor, atx

  下面貼出githup上關(guān)于該方法的使用

 

Watcher
 You can register watchers to perform some actions when a selector does not find a match.
 Register Watcher
 When a selector can not find a match, uiautomator2 will run all registered watchers.
 Click target when conditions match
 d.watcher("AUTO_FC_WHEN_ANR").when(text="ANR").when(text="Wait") \
               .click(text="Force Close")
 # d.watcher(name) ## creates a new named watcher.
 # .when(condition) ## the UiSelector condition of the watcher.
 # .click(target) ## perform click action on the target UiSelector.
 There is also a trick about click. You can use click without arguments.
 d.watcher("ALERT").when(text="OK").click()
 # Same as
 d.watcher("ALERT").when(text="OK").click(text="OK")
 Press key when a condition becomes true
 d.watcher("AUTO_FC_WHEN_ANR").when(text="ANR").when(text="Wait") \
               .press("back", "home")
 # d.watcher(name) ## creates a new named watcher.
 # .when(condition) ## the UiSelector condition of the watcher.
 # .press(<keyname>, ..., <keyname>.() ## press keys one by one in sequence.
 Check if the named watcher triggered
 A watcher is triggered, which means the watcher was run and all its conditions matched.
 d.watcher("watcher_name").triggered
 # true in case of the specified watcher triggered, else false
 Remove a named watcher
 # remove the watcher
 d.watcher("watcher_name").remove()
 List all watchers
 d.watchers
 # a list of all registered watchers
 Check for any triggered watcher
 d.watchers.triggered
 # true in case of any watcher triggered
 Reset all triggered watchers
 # reset all triggered watchers, after that, d.watchers.triggered will be false.
 d.watchers.reset()
 Remove watchers
 # remove all registered watchers
 d.watchers.remove()
 # remove the named watcher, same as d.watcher("watcher_name").remove()
 d.watchers.remove("watcher_name")
 Force to run all watchers
 # force to run all registered watchers
 d.watchers.run()

注:里面涉及的watcher_name可以自定義,可以做到見名知意即可

watcher的使用是要先注冊(第9行至20行均是注冊watcher的方法),然后激活watcher(第56行),注意這個(gè)激活方法只是一個(gè)瞬時(shí)激活,就是說使用之后即銷毀,不會一直存于后臺。那這樣的話在實(shí)際的使用場景中怎么使用這個(gè)功能呢,下面看一段腳本 1 # -*- coding:utf-8 -*-

import uiautomator2 as u2
import time
d = u2.connect()
cfg = MTBFConfig()
package = cfg.getstr("Admit", "pkg", "config")
PACKAGELIST = package.split(",")
print(PACKAGELIST)
d.watcher("‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‏‎‎‏‎‎‎‎‏‏‏‏‏‏‏‏‎‎‎‎‎‎‎‎‎‏‎‎‎‏‎‎‏‏‎‏‎‏‎‎‎‏‏‏‎‏‏‏‎‏‏‎‎‎‏‏‏‏‏‏‏‎‎‏‎‎‏‏‎‎‎‏‎‎‎‏‏‏‎ALLOW‎‏‎‎‏‎").when(text="‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‏‎‎‏‎‎‎‎‏‏‏‏‏‏‏‏‎‎‎‎‎‎‎‎‎‏‎‎‎‏‎‎‏‏‎‏‎‏‎‎‎‏‏‏‎‏‏‏‎‏‏‎‎‎‏‏‏‏‏‏‏‎‎‏‎‎‏‏‎‎‎‏‎‎‎‏‏‏‎ALLOW‎‏‎‎‏‎").click(text="‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‏‎‎‏‎‎‎‎‏‏‏‏‏‏‏‏‎‎‎‎‎‎‎‎‎‏‎‎‎‏‎‎‏‏‎‏‎‏‎‎‎‏‏‏‎‏‏‏‎‏‏‎‎‎‏‏‏‏‏‏‏‎‎‏‎‎‏‏‎‎‎‏‎‎‎‏‏‏‎ALLOW‎‏‎‎‏‎")
#d.watchers.run()
print(d.watchers)
time.sleep(2)
pkglen = len(PACKAGELIST)
print(("There are %d package for test") %pkglen)
class Admit(object):
 def main(self):
   for i in range(pkglen):
     k = 0
     for j in range(5):
       if d.info['currentPackageName'] != PACKAGELIST[i]:
         d.app_start(PACKAGELIST[i])
         print(PACKAGELIST[i])
         time.sleep(1)
         k += 1
       if k == 3:
         print("Can not enter "+ str(PACKAGELIST[i]))
         return False
     if PACKAGELIST[i] == 'com.google.android.contacts':
       print("hello")
       if d(description = "Open navigation drawer").exists(timeout = 5):
         d(description = "Open navigation drawer").click()
       if d(text = "Settings").exists(timeout = 5):
         d(text = "Settings").click()
       if d(resourceId="android:id/title", text = "Import").exists(timeout=5):
         d(resourceId="android:id/title", text = "Import").click()
         time.sleep(3)
       if d(resourceId = "android:id/button1", text = "OK").exists(timeout = 5):
         d(resourceId = "android:id/button1", text = "OK").click()
         time.sleep(1)
         d.watchers.run() //在上面OK點(diǎn)擊之后會彈出一個(gè)權(quán)限訪問的許可,所以這個(gè)時(shí)候需要激活一次watcher把彈框關(guān)掉,以便不影響后續(xù)測試,所以就一個(gè)原則,哪里可能會有彈框就在哪里激活watcher
if __name__=="__main__":
 ad = Admit()
 ad.main()

總結(jié)

以上所述是小編給大家介紹的python uiautomator2 watcher的使用方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

  • Pandas多個(gè)條件(AND,OR,NOT)中提取行

    Pandas多個(gè)條件(AND,OR,NOT)中提取行

    本文主要介紹了Pandas多個(gè)條件(AND,OR,NOT)中提取行,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-02-02
  • 詳解Anconda環(huán)境下載python包的教程(圖形界面+命令行+pycharm安裝)

    詳解Anconda環(huán)境下載python包的教程(圖形界面+命令行+pycharm安裝)

    這篇文章主要介紹了Anconda環(huán)境下載python包的教程(圖形界面+命令行+pycharm安裝),這篇文章很適合小白入手級別的,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-11-11
  • python的random和time模塊詳解

    python的random和time模塊詳解

    這篇文章主要介紹了python的random和time模塊,具有一定借鑒價(jià)值,需要的朋友可以參考下,希望能夠給你帶來幫助
    2021-10-10
  • python sys.argv[]用法實(shí)例詳解

    python sys.argv[]用法實(shí)例詳解

    sys.argv[]是用來獲取命令行參數(shù)的,sys.argv[0]表示代碼本身文件路徑,所以參數(shù)從1開始,下面通過實(shí)例給大家介紹python sys.argv[]用法,感興趣的朋友一起看看吧
    2018-05-05
  • python監(jiān)控windows服務(wù)器的進(jìn)程和服務(wù)

    python監(jiān)控windows服務(wù)器的進(jìn)程和服務(wù)

    這篇文章主要為大家詳細(xì)介紹了如何使用python監(jiān)控windows服務(wù)器的進(jìn)程和服務(wù),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2025-04-04
  • Python中使用jpype調(diào)用Jar包中的實(shí)現(xiàn)方法

    Python中使用jpype調(diào)用Jar包中的實(shí)現(xiàn)方法

    這篇文章主要介紹了Python中使用jpype調(diào)用Jar包中的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • pandas刪除重復(fù)數(shù)據(jù)簡單方法

    pandas刪除重復(fù)數(shù)據(jù)簡單方法

    這篇文章主要給大家介紹了關(guān)于pandas刪除重復(fù)數(shù)據(jù)的簡單方法,在數(shù)據(jù)處理過程中常常會遇到重復(fù)的問題,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-07-07
  • python實(shí)現(xiàn)根據(jù)用戶輸入從電影網(wǎng)站獲取影片信息的方法

    python實(shí)現(xiàn)根據(jù)用戶輸入從電影網(wǎng)站獲取影片信息的方法

    這篇文章主要介紹了python實(shí)現(xiàn)根據(jù)用戶輸入從電影網(wǎng)站獲取影片信息的方法,涉及Python正則表達(dá)式抓取網(wǎng)頁的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-04-04
  • Pytorch?PyG實(shí)現(xiàn)EdgePool圖分類

    Pytorch?PyG實(shí)現(xiàn)EdgePool圖分類

    這篇文章主要為大家介紹了Pytorch?PyG實(shí)現(xiàn)EdgePool圖分類示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-04-04
  • 使用Python編寫一個(gè)Lisp語言的解釋器

    使用Python編寫一個(gè)Lisp語言的解釋器

    這篇文章主要為大家詳細(xì)介紹了如何使用Python編寫一個(gè)簡單的Lisp語言的解釋器,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-11-11

最新評論

中阳县| 于田县| 石河子市| 黔西县| 新丰县| 富锦市| 益阳市| 类乌齐县| 龙州县| 芦山县| 丰都县| 镇巴县| 沽源县| 永宁县| 洪江市| 枞阳县| 毕节市| 桦川县| 清水河县| 县级市| 湘西| 津市市| 六安市| 湘潭县| 开原市| 瑞金市| 临邑县| 阿鲁科尔沁旗| 岐山县| 宜川县| 凤凰县| 东海县| 洛浦县| 资阳市| 灌阳县| 元阳县| 视频| 望江县| 盈江县| 连平县| 黄山市|