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:
@@ -81,6 +81,30 @@ class AutomationMassHealthEligibilityHistoryCheck:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
login_button.click()
|
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"
|
return "Success"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[login] Error: {e}")
|
print(f"[login] Error: {e}")
|
||||||
|
|||||||
@@ -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 = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[type='submit'][name='submit'][value='Login']")))
|
||||||
login_button.click()
|
login_button.click()
|
||||||
|
|
||||||
# Wait for SSO redirect to complete and land on the MassHealth portal.
|
# Wait for the SSO redirect to complete. On some machines Chrome opens
|
||||||
# Must check the hostname only — the SSO URL itself contains "provider.masshealth-dental.org"
|
# the dashboard in a NEW tab and closes the SSO tab. Poll ALL open
|
||||||
# as a query parameter, so a plain substring check would match too early.
|
# 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 ...")
|
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:
|
try:
|
||||||
WebDriverWait(self.driver, 30).until(
|
self.driver.switch_to.window(handle)
|
||||||
lambda d: d.current_url.startswith("https://provider.masshealth-dental.org")
|
if self.driver.current_url.startswith("https://provider.masshealth-dental.org"):
|
||||||
)
|
|
||||||
print(f"[login] Redirect complete. URL: {self.driver.current_url}")
|
print(f"[login] Redirect complete. URL: {self.driver.current_url}")
|
||||||
except TimeoutException:
|
found = True
|
||||||
print(f"[login] Redirect timeout. Still on: {self.driver.current_url}")
|
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 "ERROR: Login redirect timed out — check credentials or portal availability."
|
||||||
|
|
||||||
if self._is_maintenance_page():
|
if self._is_maintenance_page():
|
||||||
|
|||||||
Reference in New Issue
Block a user