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:
@@ -370,28 +370,26 @@ class AutomationCMSPEligibilityHistoryRemainingCheck:
|
|||||||
return f"ERROR:STEP6:{substep}"
|
return f"ERROR:STEP6:{substep}"
|
||||||
|
|
||||||
# ── step 7 — print accumulator PDF ──────────────────────────────────────────
|
# ── 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):
|
def step7_accumulator_pdf(self):
|
||||||
wait = WebDriverWait(self.driver, 30)
|
wait = WebDriverWait(self.driver, 60)
|
||||||
current_tab = self.driver.current_window_handle
|
|
||||||
try:
|
try:
|
||||||
# ng-click="vm.printResults()" and ng-if="vm.hasResults" identify this button
|
# Wait for the page to finish loading
|
||||||
print_button = wait.until(
|
wait.until(lambda d: d.execute_script("return document.readyState") == "complete")
|
||||||
EC.element_to_be_clickable(
|
|
||||||
|
# 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()']")
|
(By.CSS_SELECTOR, "button.btn.btn-primary[ng-click='vm.printResults()']")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
print_button.click()
|
print("[step7] accumulator data loaded (vm.hasResults is true)")
|
||||||
|
time.sleep(2) # brief pause for any final Angular digest cycle
|
||||||
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")
|
|
||||||
|
|
||||||
safe_member = "".join(c for c in str(self.memberId) if c.isalnum() or c in "-_.")
|
safe_member = "".join(c for c in str(self.memberId) if c.isalnum() or c in "-_.")
|
||||||
pdf_filename = f"cmsp_accumulator_{safe_member}.pdf"
|
pdf_filename = f"cmsp_accumulator_{safe_member}.pdf"
|
||||||
|
|||||||
Reference in New Issue
Block a user