-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactions.py
More file actions
27 lines (26 loc) · 844 Bytes
/
Copy pathactions.py
File metadata and controls
27 lines (26 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import time
from waiter import wait_for_ui_change, hash_xml, RETRYABLE
from selenium.common.exceptions import WebDriverException
def execute_with_retry(driver, action_fn, max_retry=3):
last_error = None
for attempt in range(1, max_retry + 1):
try:
before_hash = hash_xml(driver.page_source)
action_fn()
ui_changed = wait_for_ui_change(driver, before_hash)
return {
"success": True,
"attempt": attempt,
"ui_changed": ui_changed
}
except RETRYABLE as e:
last_error = e
time.sleep(0.5 * attempt)
except WebDriverException as e:
last_error = e
break
return {
"success": False,
"error": str(last_error),
"attempts": max_retry
}