fix: wait for accumulator data before CDP print in CMSP flow

step7 now waits for button[ng-click='vm.printResults()'][ng-if='vm.hasResults']
to become visible before printing — that element only renders once Angular
has loaded the accumulator data, so the CDP capture is no longer racing
against the async data fetch.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Gitead
2026-05-14 11:49:20 -04:00
parent 0628f9f7fc
commit 2baa1b0435

View File

@@ -370,28 +370,26 @@ class AutomationCMSPEligibilityHistoryRemainingCheck:
return f"ERROR:STEP6:{substep}"
# ── step 7 — print accumulator PDF ──────────────────────────────────────────
# We wait for ng-if="vm.hasResults" button to become visible — that confirms
# Angular has finished loading the accumulator data — then CDP-print directly
# to avoid the new-tab timing race that produces an empty PDF.
def step7_accumulator_pdf(self):
wait = WebDriverWait(self.driver, 30)
current_tab = self.driver.current_window_handle
wait = WebDriverWait(self.driver, 60)
try:
# ng-click="vm.printResults()" and ng-if="vm.hasResults" identify this button
print_button = wait.until(
EC.element_to_be_clickable(
# Wait for the page to finish loading
wait.until(lambda d: d.execute_script("return document.readyState") == "complete")
# Wait for the "Printer Friendly Format" button to appear — it is
# wrapped in ng-if="vm.hasResults", so it only renders once the
# accumulator data has fully loaded from the server.
wait.until(
EC.visibility_of_element_located(
(By.CSS_SELECTOR, "button.btn.btn-primary[ng-click='vm.printResults()']")
)
)
print_button.click()
try:
WebDriverWait(self.driver, 10).until(lambda d: len(d.window_handles) > 1)
new_tabs = [t for t in self.driver.window_handles if t != current_tab]
self.driver.switch_to.window(new_tabs[0])
wait.until(lambda d: d.execute_script("return document.readyState") == "complete")
wait.until(EC.presence_of_element_located((By.TAG_NAME, "body")))
time.sleep(2)
except TimeoutException:
print("No new tab for accumulator; printing current page directly")
print("[step7] accumulator data loaded (vm.hasResults is true)")
time.sleep(2) # brief pause for any final Angular digest cycle
safe_member = "".join(c for c in str(self.memberId) if c.isalnum() or c in "-_.")
pdf_filename = f"cmsp_accumulator_{safe_member}.pdf"