From 4bf80f03a8a6b499c239e57906cc3c3c9cd8c691 Mon Sep 17 00:00:00 2001 From: Dave Roberts Date: Wed, 25 Sep 2024 17:37:26 -0500 Subject: [PATCH] Replace wait with wait-predicate in test-add-script --- test/etaoin/api_test.clj | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/etaoin/api_test.clj b/test/etaoin/api_test.clj index 2c82d7d..f2a65e7 100644 --- a/test/etaoin/api_test.clj +++ b/test/etaoin/api_test.clj @@ -821,7 +821,15 @@ (let [js-url (test-server-url "js/inject.js")] (testing "adding a script" (e/add-script *driver* js-url) - (e/wait 1) + ;; We need to wait for the browser to parse the + ;; script. Running "typeof " will + ;; return "function" if the function is defined (and "undefined" + ;; if not). + (e/wait-predicate + (fn [] (= "function" (e/js-execute *driver* "return typeof injected_func;"))) + {:timeout 30 + :internval 0.1 + :message "Timeout waiting for JavaScript to be parsed"}) (let [result (e/js-execute *driver* "return injected_func();")] (is (= result "I was injected"))))))