From a783dc679701b2892b10a1e1216f6717fb2b144e Mon Sep 17 00:00:00 2001 From: "Alex.Shi" Date: Mon, 10 Aug 2020 11:12:58 +0300 Subject: [PATCH] add wrap-default-timeout && wrap-default-interval (#271) * add with-wait-timeout && with-wait-interval * update --- README.md | 19 +++++++++++++++++++ src/etaoin/api.clj | 19 +++++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c85235b4..672a171b 100644 --- a/README.md +++ b/README.md @@ -1431,6 +1431,25 @@ The final form would be something like this: ...etc)) ``` +In addition to `with-wait` and `do-wait` there are a number of waiting functions: +`wait-visible`, `wait-has-alert`, `wait-predicate`, etc (see the full list in the +[corresponsing section](http://etaoin.grishaev.me/etaoin.api.html#var-wait)). They +accept default timeout/interval values that can be redefined using the +`with-wait-timeout` and `with-wait-interval` macros, respectively. + +Example from etaoin test: +``` clojure +(deftest test-wait-has-text + (testing "wait for text simple" + (with-wait-timeout 15 ;; time in seconds + (doto *driver* + (refresh) + (wait-visible {:id :document-end}) + (click {:id :wait-button}) + (wait-has-text :wait-span "-secret-")) + (is true "text found")))) +``` + ## Writing Integration Tests For Your Application ### Basic fixture diff --git a/src/etaoin/api.clj b/src/etaoin/api.clj index 044f5f81..9e47e91a 100644 --- a/src/etaoin/api.clj +++ b/src/etaoin/api.clj @@ -2033,8 +2033,19 @@ ;; wait functions ;; -(def default-timeout 20) -(def default-interval 0.33) +(def ^:dynamic *wait-timeout* 20) +(def ^:dynamic *wait-interval* 0.33) + + +(defmacro with-wait-timeout + [sec & body] + `(binding [*wait-timeout* ~sec] + ~@body)) + +(defmacro with-wait-interval + [sec & body] + `(binding [*wait-interval* ~sec] + ~@body)) (defn wait "Sleeps for N seconds." @@ -2072,9 +2083,9 @@ ([pred] (wait-predicate pred {})) ([pred opt] - (let [timeout (get opt :timeout default-timeout) ;; refactor this (call for java millisec) + (let [timeout (get opt :timeout *wait-timeout*) ;; refactor this (call for java millisec) time-rest (get opt :time-rest timeout) - interval (get opt :interval default-interval) + interval (get opt :interval *wait-interval*) times (get opt :times 0) message (get opt :message)] (when (< time-rest 0)