Python編程_Selenium2Library源碼分析

來源:互聯網
上載者:User

標籤:函數嵌套   for   傳遞   函數   erro   bsp   max   log   調用   

[Package] keywords

所有關鍵字封裝

[Class] _waiting.py

等待函數的條件判斷, 替換sleep, 在依次以條件邏輯執行較多用例時可以有效節省執行等待時間, 快速定位問題

_wait_until(self, timeout, error, function, *args)

概述: 直到function(*args)為True時return None, 為False則return error, 逾時時間timeout

參數:

  error: 初始化為逾時異常

  function: 條件判斷, 返回True or False  

return: None or error

1     def _wait_until(self, timeout, error, function, *args):2         error = error.replace(‘<TIMEOUT>‘, self._format_timeout(timeout))3         def wait_func():4             return None if function(*args) else error5         self._wait_until_no_error(timeout, wait_func)

 

_wait_until_no_error(self, timeout, wait_func, *args)

概述: 直到wait_func(*args)為False時return, 逾時則拋出逾時異常

 

1     def _wait_until_no_error(self, timeout, wait_func, *args):2         timeout = robot.utils.timestr_to_secs(timeout) if timeout is not None else self._timeout_in_secs3         maxtime = time.time() + timeout4         while True:5             timeout_error = wait_func(*args)6             if not timeout_error: return7             if time.time() > maxtime:8                 raise AssertionError(timeout_error)9             time.sleep(0.2)

 

 最終調用的都是_wait_until_no_error(self, timeout, wait_func, *args). 在層層調用中, 使用到的Python文法, 一是函數嵌套, 而是"一切皆為對象", 函數也可做參數傳遞

Python編程_Selenium2Library源碼分析

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.