pipshowuiautomator2Name:uiautomator2Version:1.2.2Summary:PythonWrapperforAndroidUiAutomator2testtoolHome-page:https://github.com/codeskyblue/uiautomator2Author:codeskyblueAuthor-ema" />

欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

詳解python uiautomator2 watcher的使用方法

系統(tǒng) 1608 0

該方是基于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(
            
              , ..., 
              
                .() ## 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可以自定義,可以做到見(jiàn)名知意即可

watcher的使用是要先注冊(cè)(第9行至20行均是注冊(cè)watcher的方法),然后激活watcher(第56行),注意這個(gè)激活方法只是一個(gè)瞬時(shí)激活,就是說(shuō)使用之后即銷(xiāo)毀,不會(huì)一直存于后臺(tái)。那這樣的話在實(shí)際的使用場(chǎng)景中怎么使用這個(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)擊之后會(huì)彈出一個(gè)權(quán)限訪問(wèn)的許可,所以這個(gè)時(shí)候需要激活一次watcher把彈框關(guān)掉,以便不影響后續(xù)測(cè)試,所以就一個(gè)原則,哪里可能會(huì)有彈框就在哪里激活watcher
if __name__=="__main__":
 ad = Admit()
 ad.main()
          

總結(jié)

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


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!?。?/p>

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 韩日a级片| 国产精品高清在线 | 亚洲成片在线观看12345ba | 久久福利青草精品资源 | 我要看欧美一级毛片 | 韩国女主播青草在线观看 | 成人欧美一区二区三区在线观看 | 国内精品视频区在线2021 | 91手机在线视频观看 | 精品欧美在线观看 | 欧美精品国产综合久久 | 黄色网在线播放 | 亚洲黄色第一页 | 日韩中文字幕一区 | 国产小视频精品 | 日日操夜夜爽 | 色综合区 | 91影院 | 亚洲国产成人九九综合 | 欧美狂猛xxxxx乱大交3 | 四虎影视最新网站在线播放 | 奶子吧naiziba.cc免费午夜片在线观看 | 欧美精品日韩一区二区三区 | 日韩在线观看你懂的 | 精品久久久久久免费影院 | 日韩v在线 | 国产香港一级毛片在线看 | 国产免费一区二区 | 91 在线| 国产欧美日韩在线播放 | 久久久久久亚洲精品 | 国产一区亚洲一区 | 亚洲婷婷综合中文字幕第一页 | 欧美成人在线视频 | 91大神精品长腿在线观看网站 | 国产精品一区久久久 | 日日干日日插 | 九九视频精品全部免费播放 | 国产精品a久久久久 | 亚洲黄色高清视频 | 国产在线综合一区二区三区 |