From cc9975aaf03f31e5dd067c2cac7c4906a313cd43 Mon Sep 17 00:00:00 2001 From: giles Date: Fri, 17 Apr 2026 21:45:38 +0000 Subject: [PATCH] Add wait-for-el polling to test runner for element readiness wait-for-el polls the iframe doc for a CSS selector up to max-tries times with 200ms intervals. Used before running test actions to ensure the target elements exist in the iframe after page load. Also restores reload-frame timing and keeps cek-try error handling. Co-Authored-By: Claude Opus 4.6 (1M context) --- sx/sx/applications/htmx/runner.sx | 34 ++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/sx/sx/applications/htmx/runner.sx b/sx/sx/applications/htmx/runner.sx index e472b787..3c8c4809 100644 --- a/sx/sx/applications/htmx/runner.sx +++ b/sx/sx/applications/htmx/runner.sx @@ -24,15 +24,29 @@ "true")) true (do (hs-wait 200) (wait-boot)))))) - (reload-frame - (fn - () - (let - ((w (host-get (dom-query "#test-iframe") "contentWindow"))) - (host-call (host-get w "location") "reload") - (hs-wait 1000) - (wait-boot) - (hs-wait 500)))) + (begin + (reload-frame + (fn + () + (let + ((w (host-get (dom-query "#test-iframe") "contentWindow"))) + (host-call (host-get w "location") "reload") + (hs-wait 1000) + (wait-boot) + (hs-wait 500)))) + (wait-for-el + (fn + (sel max-tries) + (let + ((doc (get-doc)) + (el (when doc (host-call doc "querySelector" sel)))) + (if + el + el + (if + (<= max-tries 0) + nil + (do (hs-wait 200) (wait-for-el sel (- max-tries 1))))))))) (run-action (fn (action) @@ -106,7 +120,7 @@ (reset! results (assoc (deref results) name "running")) (reload-frame) (let - ((test-ok (cek-try (fn () (for-each run-action (get test :actions)) true) (fn (e) (do (reset! results (assoc (deref results) name "fail")) (console-log (str "FAIL " name ": " e)) false))))) + ((test-ok (cek-try (fn () (let ((actions (get test :actions))) (when (not (empty? actions)) (let ((first-sel (nth (first actions) 1))) (when (string? first-sel) (let ((found (wait-for-el first-sel 15))) (when (nil? found) (error (str "Timeout waiting for: " first-sel))))))) (for-each run-action actions)) true) (fn (e) (do (reset! results (assoc (deref results) name "fail")) (console-log (str "FAIL " name ": " e)) false))))) (when test-ok (reset! results (assoc (deref results) name "pass"))))))