最近用robotframework 自帶的selenium庫關鍵字進行頁面腳本編寫測試,發現有很多等待關鍵字,等待條件成立或時間結束后返回,本人之前一直在思考等待命令執行一定時間在接着執行,
認為可以借鑒次代碼,將此處代碼復制粘貼在博客上。
def _wait_until_worker(self, condition, timeout, error):
max_time = time.time() + timeout
not_found = None
while time.time() < max_time:
try:
if condition():
return
except ElementNotFound as err:
not_found = str(err)
else:
not_found = None
time.sleep(0.2)
raise AssertionError(not_found or error)
