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) <noreply@anthropic.com>
This commit is contained in:
@@ -24,15 +24,29 @@
|
|||||||
"true"))
|
"true"))
|
||||||
true
|
true
|
||||||
(do (hs-wait 200) (wait-boot))))))
|
(do (hs-wait 200) (wait-boot))))))
|
||||||
(reload-frame
|
(begin
|
||||||
(fn
|
(reload-frame
|
||||||
()
|
(fn
|
||||||
(let
|
()
|
||||||
((w (host-get (dom-query "#test-iframe") "contentWindow")))
|
(let
|
||||||
(host-call (host-get w "location") "reload")
|
((w (host-get (dom-query "#test-iframe") "contentWindow")))
|
||||||
(hs-wait 1000)
|
(host-call (host-get w "location") "reload")
|
||||||
(wait-boot)
|
(hs-wait 1000)
|
||||||
(hs-wait 500))))
|
(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
|
(run-action
|
||||||
(fn
|
(fn
|
||||||
(action)
|
(action)
|
||||||
@@ -106,7 +120,7 @@
|
|||||||
(reset! results (assoc (deref results) name "running"))
|
(reset! results (assoc (deref results) name "running"))
|
||||||
(reload-frame)
|
(reload-frame)
|
||||||
(let
|
(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
|
(when
|
||||||
test-ok
|
test-ok
|
||||||
(reset! results (assoc (deref results) name "pass"))))))
|
(reset! results (assoc (deref results) name "pass"))))))
|
||||||
|
|||||||
Reference in New Issue
Block a user