Skip to content

Commit

Permalink
add wrap-default-timeout && wrap-default-interval (#271)
Browse files Browse the repository at this point in the history
* add with-wait-timeout && with-wait-interval

* update
  • Loading branch information
Uunnamed authored Aug 10, 2020
1 parent b65d721 commit a783dc6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions src/etaoin/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a783dc6

Please sign in to comment.