hopefully fixed the success dialog close issue

This commit is contained in:
2026-07-07 13:01:52 -05:00
parent 9e303d01c9
commit 1f4555bff6

View File

@@ -146,41 +146,52 @@ def perform_export(dlg, ctrl, timeouts):
def dismiss_any_dialog(app, ctrl, log): def dismiss_any_dialog(app, ctrl, log):
"""Try to find and dismiss any stale dialogs left from a previous failure.""" """Try to find and dismiss any stale dialogs left from a previous failure."""
try: # Dismiss "Send to" confirmation dialog (OK)
for w in app.windows(): w = _find_desktop_dialog("Send to")
if not (w.class_name() == "#32770" and w.is_visible()): if w:
continue try:
title = w.window_text() _click_dialog_button(w, "OK", log)
# Dismiss the Send To File dialog (Cancel) log(" Dismissed stale confirmation dialog.")
if title == ctrl["dialog_title"]: except Exception:
try: pass
w.child_window(title="Cancel", class_name="Button").click()
log(f" Dismissed stale Send To File dialog.") # Dismiss Send To File Location dialog (Cancel)
time.sleep(0.5) w = _find_desktop_dialog(ctrl["dialog_title"])
except Exception: if w:
pass try:
continue _click_dialog_button(w, "Cancel", log)
# Dismiss any other dialog (OK) log(" Dismissed stale Send To File dialog.")
try: except Exception:
w.child_window(title="OK", class_name="Button").click() pass
log(f" Dismissed stale dialog: {title!r}")
time.sleep(0.5)
except Exception: def _find_desktop_dialog(title_match):
pass """Search all top-level windows for a visible #32770 dialog matching title."""
except Exception: for w in Desktop(backend="win32").windows():
pass try:
if w.class_name() == "#32770" and w.is_visible() and title_match in w.window_text():
return w
except Exception:
continue
return None
def _click_dialog_button(dialog, button_title, log):
"""Connect to a desktop dialog and click a button on it."""
app = Application(backend="win32").connect(handle=dialog.handle)
dlg = app.window(handle=dialog.handle)
dlg.child_window(title=button_title, class_name="Button").click()
dlg.wait_not("visible", timeout=10)
def wait_for_export(app, ctrl, timeouts, log): def wait_for_export(app, ctrl, timeouts, log):
""" """
Wait for the full export lifecycle to complete: Wait for the full export lifecycle to complete:
1. 'Exporting Documents' progress dialog appears (export running) 1. 'Exporting Documents' progress dialog appears (export running)
2. Progress dialog disappears (export finished writing files) 2. Poll until '"Send to" file saved' confirmation dialog appears
3. '"Send to" file saved' confirmation dialog appears (MODAL) 3. Click OK to dismiss it
4. Dismiss it by clicking OK
""" """
progress = app.window(title=ctrl["progress_title"], class_name=ctrl["progress_class"]) progress = app.window(title=ctrl["progress_title"], class_name=ctrl["progress_class"])
saved = app.window(title=ctrl["saved_title"], class_name=ctrl["saved_class"])
try: try:
progress.wait("visible", timeout=timeouts["progress_appear"]) progress.wait("visible", timeout=timeouts["progress_appear"])
@@ -189,51 +200,24 @@ def wait_for_export(app, ctrl, timeouts, log):
log(" NOTE: progress dialog not seen; checking for confirmation dialog " log(" NOTE: progress dialog not seen; checking for confirmation dialog "
"(drawer may have exported very quickly).") "(drawer may have exported very quickly).")
# Poll until the confirmation dialog appears OR we time out. # Poll the entire desktop for the confirmation dialog.
# We do NOT rely on wait_not for the progress dialog because it can # app.window() can miss it — the dialog may not be owned by the app.
# briefly disappear and reappear during long exports.
deadline = time.time() + timeouts["progress_finish"] deadline = time.time() + timeouts["progress_finish"]
saved_win = None
while time.time() < deadline: while time.time() < deadline:
# Check if the confirmation dialog has appeared saved_win = _find_desktop_dialog("Send to")
if saved.exists(timeout=0): if saved_win is not None:
break break
time.sleep(2) time.sleep(2)
else:
log(f" ERROR: export did not finish within {timeouts['progress_finish']}s.") if saved_win is None:
log(f" ERROR: confirmation dialog never appeared within {timeouts['progress_finish']}s.")
return False return False
try: log(f" Confirmation dialog found: {saved_win.window_text()!r}")
saved.wait("visible ready", timeout=timeouts["confirm"])
log(" Confirmation dialog appeared - export succeeded.")
except timings.TimeoutError:
# Fallback: look for any #32770 dialog that appeared (title may differ)
log(" WARNING: expected confirmation dialog not found by title. "
"Checking for any popup dialog...")
found = False
try:
for w in app.windows():
if w.class_name() == "#32770" and w.is_visible():
log(f" Found dialog: {w.window_text()!r}")
try:
w.child_window(title="OK", class_name="Button").click()
w.wait_not("visible", timeout=10)
log(" Dismissed via fallback.")
found = True
break
except Exception:
pass
except Exception:
pass
if not found:
log(" ERROR: confirmation dialog never appeared. Export may have "
"failed or produced no output.")
return False
log(" Export complete.")
return True
try: try:
saved.child_window(title=ctrl["saved_ok_title"], class_name="Button").click() _click_dialog_button(saved_win, "OK", log)
saved.wait_not("visible", timeout=timeouts["confirm"])
log(" Confirmation dismissed.") log(" Confirmation dismissed.")
except Exception as e: except Exception as e:
log(f" WARNING: could not dismiss confirmation dialog: {e}") log(f" WARNING: could not dismiss confirmation dialog: {e}")