Skip to content

Commit 53ed97e

Browse files
test: enhance initial setup in HomePageTest to handle alerts more robustly and improve error logging
1 parent 1e2eaa4 commit 53ed97e

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

tests/test_home_page.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,24 @@ def _take_screenshot(self, name_suffix):
7171

7272
def _initial_setup(self): # Removed driver argument
7373
self.driver.get(self.BASE_URL) # Use BASE_URL
74-
# Initial alert handling commented out as it might not be relevant for the new HTML
75-
# try:
76-
# WebDriverWait(self.driver, 3).until(
77-
# EC.element_to_be_clickable((By.CSS_SELECTOR, ".alert__button.alert__button--single"))
78-
# ).click()
79-
# logger.info("Initial alert handled.")
80-
# except TimeoutException:
81-
# logger.info("Initial alert not found or not clickable, proceeding.")
74+
75+
# Attempt to handle an initial alert/overlay
76+
try:
77+
# Assuming the button to close the alert has the selector ".alert__button.alert__button--single"
78+
# This selector might need to be confirmed if issues persist.
79+
alert_button_selector = ".alert__button.alert__button--single"
80+
alert_button = WebDriverWait(self.driver, 5).until( # Using wait_short's timeout
81+
EC.element_to_be_clickable((By.CSS_SELECTOR, alert_button_selector))
82+
)
83+
alert_button.click()
84+
logger.info(f"Initial alert with button '{alert_button_selector}' handled.")
85+
# Wait a very short moment for the overlay to disappear
86+
time.sleep(0.5)
87+
except TimeoutException:
88+
logger.info("Initial alert/overlay button not found or not clickable within timeout, proceeding.")
89+
except Exception as e:
90+
logger.warning(f"An unexpected error occurred while trying to handle initial alert: {e}")
91+
# self._take_screenshot("error_initial_alert_handling") # Optional: screenshot if alert handling fails unexpectedly
8292

8393
try:
8494
self.wait_long.until(EC.presence_of_element_located((By.CSS_SELECTOR, self.GRADE_INPUT_SELECTOR)))

0 commit comments

Comments
 (0)