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

fix wait-has-text #274

Merged
merged 4 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 16 additions & 2 deletions src/etaoin/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2197,16 +2197,30 @@
Arguments:

- `driver`: a driver instance;
- `q`: a query term (see `query`);
- `q`: a query term (see `query`).
- `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"
q text)]
(wait-predicate #(has-text? driver q text)
(assoc opt :message message))))

(defn wait-has-text-everywhere
Copy link
Collaborator

@igrishaev igrishaev Aug 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

может, здесь пробросить параметры в wait-has-text?

(wait-has-text driver {:xpath "*"} text opt)

Я помню, что еще до этого говорил, что лучше не завязывать функции друг на друга. Но в тот раз я не был уверен в поведении, а тут все должно быть нормально.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И добавить прмер в readme

"Like `wait-has-text` but searches for text across the entire page.

Arguments:

- `driver`: a driver instance;
- `text`: a string to search;
- `opt`: a map of options (see `wait-predicate`)."
[driver text & [opt]]
(let [q {:xpath "*"}
message (format "Wait for %s element has text %s"
q text)]
(wait-predicate #(has-text? driver q text)
(assoc opt :message message))))

(defn wait-has-class
"Waits until an element has specific class.

Expand Down
42 changes: 42 additions & 0 deletions test/etaoin/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,48 @@
:interval 0.33
:times 7}))))))

(deftest test-wait-has-text-everywhere
(testing "wait for text simple"
(doto *driver*
(refresh)
(wait-visible {:id :document-end})
(click {:id :wait-button})
(wait-has-text-everywhere "-secret-"))
(is true "text found"))
(testing "wait for text timeout"
(doto *driver*
(refresh)
(wait-visible {:id :document-end})
(click {:id :wait-button}))
(try+
(wait-has-text-everywhere *driver*
"-secret-"
{:timeout 1})
(is false "should not be executed")
(catch [:type :etaoin/timeout] data
(is (= (-> data (dissoc :predicate :time-rest))
{:type :etaoin/timeout
:message "Wait for {:xpath \"*\"} element has text -secret-"
:timeout 1
:interval 0.33
:times 4})))))
(testing "wait for non-existing text"
(doto *driver*
(refresh)
(wait-visible {:id :document-end}))
(try+
(wait-has-text-everywhere *driver*
"-dunno-whatever-foo-bar-"
{:timeout 2})
(is false "should not be executed")
(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-"
:timeout 2
:interval 0.33
:times 7}))))))

(deftest test-wait-has-class
(is 1)
(testing "wait for an element has class"
Expand Down