From 33dded18135e0b3fe2494b562a755eaf337ee60c Mon Sep 17 00:00:00 2001 From: Gitead Date: Thu, 14 May 2026 11:54:46 -0400 Subject: [PATCH] fix: cap accumulator wait at 15s, always print after 5s render pause MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- ..._eligibilityHistoryRemainingCheckWorker.py | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/apps/SeleniumService/selenium_CMSP_eligibilityHistoryRemainingCheckWorker.py b/apps/SeleniumService/selenium_CMSP_eligibilityHistoryRemainingCheckWorker.py index 83aaa212..bc675966 100644 --- a/apps/SeleniumService/selenium_CMSP_eligibilityHistoryRemainingCheckWorker.py +++ b/apps/SeleniumService/selenium_CMSP_eligibilityHistoryRemainingCheckWorker.py @@ -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"