diff --git a/apps/SeleniumService/selenium_MH_eligibilityHistoryCheckWorker.py b/apps/SeleniumService/selenium_MH_eligibilityHistoryCheckWorker.py index c304f25a..bc22d80a 100644 --- a/apps/SeleniumService/selenium_MH_eligibilityHistoryCheckWorker.py +++ b/apps/SeleniumService/selenium_MH_eligibilityHistoryCheckWorker.py @@ -81,6 +81,30 @@ class AutomationMassHealthEligibilityHistoryCheck: ) ) login_button.click() + + # Wait for the SSO redirect. On some machines Chrome opens the dashboard + # in a new tab and closes the SSO tab — poll ALL window handles. + print("[login] Waiting for SSO redirect to provider.masshealth-dental.org ...") + deadline = time.time() + 30 + found = False + while time.time() < deadline: + time.sleep(0.5) + for handle in self.driver.window_handles: + try: + self.driver.switch_to.window(handle) + if self.driver.current_url.startswith("https://provider.masshealth-dental.org"): + print(f"[login] Redirect complete. URL: {self.driver.current_url}") + found = True + break + except Exception: + continue + if found: + break + + if not found: + print("[login] Redirect timeout — portal window not found in any tab.") + return "ERROR: Login redirect timed out — check credentials or portal availability." + return "Success" except Exception as e: print(f"[login] Error: {e}") diff --git a/apps/SeleniumService/selenium_eligibilityCheckWorker.py b/apps/SeleniumService/selenium_eligibilityCheckWorker.py index ce651dbc..019d664b 100755 --- a/apps/SeleniumService/selenium_eligibilityCheckWorker.py +++ b/apps/SeleniumService/selenium_eligibilityCheckWorker.py @@ -96,17 +96,28 @@ class AutomationMassHealthEligibilityCheck: login_button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[type='submit'][name='submit'][value='Login']"))) login_button.click() - # Wait for SSO redirect to complete and land on the MassHealth portal. - # Must check the hostname only — the SSO URL itself contains "provider.masshealth-dental.org" - # as a query parameter, so a plain substring check would match too early. + # Wait for the SSO redirect to complete. On some machines Chrome opens + # the dashboard in a NEW tab and closes the SSO tab. Poll ALL open + # window handles so we find the portal regardless of which tab it lands on. print("[login] Waiting for SSO redirect to provider.masshealth-dental.org ...") - try: - WebDriverWait(self.driver, 30).until( - lambda d: d.current_url.startswith("https://provider.masshealth-dental.org") - ) - print(f"[login] Redirect complete. URL: {self.driver.current_url}") - except TimeoutException: - print(f"[login] Redirect timeout. Still on: {self.driver.current_url}") + deadline = time.time() + 30 + found = False + while time.time() < deadline: + time.sleep(0.5) + for handle in self.driver.window_handles: + try: + self.driver.switch_to.window(handle) + if self.driver.current_url.startswith("https://provider.masshealth-dental.org"): + print(f"[login] Redirect complete. URL: {self.driver.current_url}") + found = True + break + except Exception: + continue + if found: + break + + if not found: + print("[login] Redirect timeout — portal window not found in any tab.") return "ERROR: Login redirect timed out — check credentials or portal availability." if self._is_maintenance_page():