fix: handle new-tab SSO redirect for MassHealth eligibility and history

After login, Chrome on some machines opens the portal dashboard in a new
tab and closes the SSO tab. Poll all window handles until the portal URL
is found, then switch to it — works for both same-tab and new-tab redirects.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Gitead
2026-05-20 08:52:11 -04:00
parent 7284598c97
commit a03f3f25dd
2 changed files with 45 additions and 10 deletions

View File

@@ -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():