Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 42 additions & 20 deletions infrasonar_selenium/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from selenium.common.exceptions import WebDriverException


MAX_RETRIES = 2


class TestBase(abc.ABC):
url: str
description: str
Expand Down Expand Up @@ -35,30 +38,49 @@ def run(cls, name: str | None = None,
command_executor="http://localhost:4444")

t0 = time.time()
success = True
error = None
retries = MAX_RETRIES

try:
driver.get(cls.url)
cls.test(driver)
except WebDriverException as e:
success = False
error = e.msg or type(e).__name__
except Exception as e:
success = False
error = str(e) or type(e).__name__
while True:
try:
driver.get(cls.url)
cls.test(driver)

success = True
error = None
break
except WebDriverException as e:
if retries:
retries -= 1
time.sleep(1.0)
try:
# reset browser to restart clean
driver.delete_all_cookies()
driver.get("about:blank")
except Exception:
pass
continue
success = False
error = e.msg or type(e).__name__
break
except Exception as e:
success = False
error = str(e) or type(e).__name__
break

return {
'name': name or cls.__name__, # str
'test': cls.__name__, # str
'url': cls.url, # str
'success': success, # int
'error': error, # str?
'duration': time.time() - t0, # float
'description': cls.description, # str
'version': cls.version, # str
'connection_retries': MAX_RETRIES-retries, # int
}
finally:
driver.quit()
return {
'name': name or cls.__name__, # str
'test': cls.__name__, # str
'url': cls.url, # str
'success': success, # int
'error': error, # str?
'duration': time.time() - t0, # float
'description': cls.description, # str
'version': cls.version, # str
}

@classmethod
def print_run(cls, name: str | None = None,
Expand Down
Loading