fix: cap accumulator wait at 15s, always print after 5s render pause
Previously waited up to 60s for vm.hasResults button causing long freeze. Now caps at 15s then always proceeds — captures data or no-results state. Extra 5s sleep ensures Angular finishes rendering table rows before CDP print. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -370,26 +370,29 @@ 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, 60)
|
||||
try:
|
||||
# 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()']")
|
||||
)
|
||||
# Wait for the page shell to load
|
||||
WebDriverWait(self.driver, 30).until(
|
||||
lambda d: d.execute_script("return document.readyState") == "complete"
|
||||
)
|
||||
print("[step7] accumulator data loaded (vm.hasResults is true)")
|
||||
time.sleep(2) # brief pause for any final Angular digest cycle
|
||||
|
||||
# Try to detect when Angular data is ready (button has ng-if="vm.hasResults").
|
||||
# Cap at 15 s — if the patient has no accumulator data the button never
|
||||
# appears and we still want to capture whatever the page shows.
|
||||
try:
|
||||
WebDriverWait(self.driver, 15).until(
|
||||
EC.visibility_of_element_located(
|
||||
(By.CSS_SELECTOR, "button.btn.btn-primary[ng-click='vm.printResults()']")
|
||||
)
|
||||
)
|
||||
print("[step7] vm.hasResults is true — data loaded")
|
||||
except TimeoutException:
|
||||
print("[step7] print button not visible after 15 s — patient may have no accumulator data, printing anyway")
|
||||
|
||||
# Extra pause so Angular finishes rendering table rows
|
||||
time.sleep(5)
|
||||
|
||||
safe_member = "".join(c for c in str(self.memberId) if c.isalnum() or c in "-_.")
|
||||
pdf_filename = f"cmsp_accumulator_{safe_member}.pdf"
|
||||
|
||||
Reference in New Issue
Block a user