Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait messages #365

Merged
merged 3 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions src/etaoin/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2336,7 +2336,9 @@
- `opt`: a map of options (see `wait-predicate`)."

[driver q & [opt]]
(wait-predicate #(exists? driver q) opt))
(let [message (format "Wait until %s element exists" q)]
(wait-predicate #(exists? driver q)
(merge {:message message} opt))))

(defn wait-absent
"Waits until an element is absent.
Expand All @@ -2348,9 +2350,9 @@
- `opt`: a map of options (see `wait-predicate`)."

[driver q & [opt]]
(let [message (format "Wait for %s element is absent" q)]
(let [message (format "Wait until %s element is absent" q)]
(wait-predicate #(absent? driver q)
(assoc opt :message message))))
(merge {:message message} opt))))

(defn wait-visible
"Waits until an element presents and is visible.
Expand All @@ -2362,9 +2364,9 @@
- `opt`: a map of options (see `wait-predicate`)."

[driver q & [opt]]
(let [message (format "Wait for %s element is visible" q)]
(let [message (format "Wait until %s element is visible" q)]
(wait-predicate #(visible? driver q)
(assoc opt :message message))))
(merge {:message message} opt))))

(defn wait-invisible
"Waits until an element presents but not visible.
Expand All @@ -2376,7 +2378,9 @@
- `opt`: a map of options (see `wait-predicate`)."

[driver q & [opt]]
(wait-predicate #(invisible? driver q) opt))
(let [message (format "Wait until %s element is invisible" q)]
(wait-predicate #(invisible? driver q)
(merge {:message message} opt))))

(defn wait-enabled
"Waits until an element is enabled (usually an input element).
Expand All @@ -2388,7 +2392,9 @@
- `opt`: a map of options (see `wait-predicate`)."

[driver q & [opt]]
(wait-predicate #(enabled? driver q) opt))
(let [message (format "Wait until %s element is enabled" q)]
(wait-predicate #(enabled? driver q)
(merge {:message message} opt))))

(defn wait-disabled
"Waits until an element is disabled (usually an input element).
Expand All @@ -2400,19 +2406,22 @@
- `opt`: a map of options (see `wait-predicate`)."

[driver q & [opt]]
(wait-predicate #(disabled? driver q) opt))
(let [message (format "Wait until %s element is disabled" q)]
(wait-predicate #(disabled? driver q)
(merge {:message message} opt))))

(defn wait-has-alert
"Waits until an alert dialog appears on the screen.

Arguments:

- `driver`: a driver instance;
- `q`: a query term (see `query`);
- `opt`: a map of options (see `wait-predicate`)."

[driver & [opt]]
(wait-predicate #(has-alert? driver) opt))
(let [message "Wait until element has alert"]
(wait-predicate #(has-alert? driver)
(merge {:message message} opt))))

(defn wait-has-text
"Waits until an element has text anywhere inside it (including inner HTML).
Expand All @@ -2424,10 +2433,10 @@
- `text`: a string to search;
- `opt`: a map of options (see `wait-predicate`)."
[driver q text & [opt]]
(let [message (format "Wait for %s element has text %s"
(let [message (format "Wait until %s element has text %s"
q text)]
(wait-predicate #(has-text? driver q text)
(assoc opt :message message))))
(merge {:message message} opt))))

(defn wait-has-text-everywhere
"Like `wait-has-text` but searches for text across the entire page.
Expand All @@ -2452,7 +2461,10 @@
- `opt`: a map of options (see `wait-predicate`)."

[driver q class & [opt]]
(wait-predicate #(has-class? driver q class) opt))
(let [message (format "Wait until %s element has class %s"
q class)]
(wait-predicate #(has-class? driver q class)
(merge {:message message} opt))))

(defn wait-running [driver & [opt]]
(log/debugf "Waiting for %s:%s is running"
Expand Down
8 changes: 4 additions & 4 deletions test/etaoin/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
(catch [:type :etaoin/timeout] data
(is (= (-> data (dissoc :predicate :time-rest))
{:type :etaoin/timeout
:message "Wait for :wait-span element has text -secret-"
:message "Wait until :wait-span element has text -secret-"
:timeout 1
:interval 0.33
:times 4})))))
Expand All @@ -299,7 +299,7 @@
(catch [:type :etaoin/timeout] data
(is (= (-> data (dissoc :predicate :time-rest))
{:type :etaoin/timeout
:message "Wait for :wait-span element has text -dunno-whatever-foo-bar-"
:message "Wait until :wait-span element has text -dunno-whatever-foo-bar-"
:timeout 2
:interval 0.33
:times 7}))))))
Expand All @@ -325,7 +325,7 @@
(catch [:type :etaoin/timeout] data
(is (= (-> data (dissoc :predicate :time-rest))
{:type :etaoin/timeout
:message "Wait for {:xpath \"*\"} element has text -secret-"
:message "Wait until {:xpath \"*\"} element has text -secret-"
:timeout 1
:interval 0.33
:times 4})))))
Expand All @@ -341,7 +341,7 @@
(catch [:type :etaoin/timeout] data
(is (= (-> data (dissoc :predicate :time-rest))
{:type :etaoin/timeout
:message "Wait for {:xpath \"*\"} element has text -dunno-whatever-foo-bar-"
:message "Wait until {:xpath \"*\"} element has text -dunno-whatever-foo-bar-"
:timeout 2
:interval 0.33
:times 7}))))))
Expand Down