Skip to content

Commit

Permalink
Catch all web driver exception types instead of just timeouts
Browse files Browse the repository at this point in the history
Obtain a screenshot on a best-effort basis
  • Loading branch information
smkent committed Jul 13, 2023
1 parent 5ddd2b8 commit e37471e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions safeway_coupons/session.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
import json
import time
import urllib
Expand All @@ -10,7 +11,7 @@
from selenium.common.exceptions import (
NoSuchElementException,
StaleElementReferenceException,
TimeoutException,
WebDriverException,
)
from selenium.webdriver.remote.webdriver import By
from selenium.webdriver.support.wait import WebDriverWait
Expand All @@ -24,7 +25,7 @@ def __init__(
self,
*args: Any,
attachments: Optional[List[Path]] = None,
**kwargs: Any
**kwargs: Any,
):
self.attachments = attachments

Expand Down Expand Up @@ -156,14 +157,15 @@ def _login(self, account: Account) -> None:
]
except Exception as e:
raise Exception("Unable to retrieve store ID") from e
except TimeoutException as e:
except WebDriverException as e:
attachments: List[Path] = []
if self.debug_dir:
path = self.debug_dir / "screenshot.png"
driver.save_screenshot(path)
attachments.append(path)
with contextlib.suppress(WebDriverException):
driver.save_screenshot(path)
attachments.append(path)
raise ExceptionWithAttachments(
"Browser authentication timed out", attachments=attachments
f"[{type(e).__name__}] {e}", attachments=attachments
) from e

def _parse_cookie_value(self, value: str) -> Any:
Expand Down

0 comments on commit e37471e

Please sign in to comment.