Skip to content

Commit

Permalink
Update wait-url-change to wait for URL to match a regex
Browse files Browse the repository at this point in the history
In addition to waiting for the URL to change, wait-url-change also
waits for the new URL to match a regex (with re-find).
  • Loading branch information
dgr committed Sep 24, 2024
1 parent 18169d3 commit 3b1e29c
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions test/etaoin/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,14 @@
(e/wait-visible *driver* {:id :document-end}))

(defmacro wait-url-change
[& body]
[re & body]
`(let [old-url# (e/get-url *driver*)]
~@body
(e/wait-predicate (fn [] (not= old-url# (e/get-url *driver*)))
(e/wait-predicate (fn [] (let [new-url# (e/get-url *driver*)]
(and (not= old-url# new-url#)
(re-find ~re new-url#))))
{:timeout 30 ; 30 second timeout total
:interval 0.100 ;
:interval 0.100 ; poll at 100 msec interval
:message "Timeout waiting for URL change"})))

(deftest test-browser-conditionals
Expand Down Expand Up @@ -204,7 +206,7 @@
(e/fill-multi *driver* {:simple-input 1
:simple-password 2
:simple-textarea 3})
(wait-url-change
(wait-url-change #"login"
(e/submit *driver* :simple-input))
(is (str/ends-with? (e/get-url *driver*) "?login=1&password=2&message=3")))

Expand All @@ -214,14 +216,14 @@
(e/fill-multi *driver* {:simple-input 1
:simple-password 2
:simple-textarea 3})
(wait-url-change (e/click *driver* :simple-submit))
(wait-url-change #"login" (e/click *driver* :simple-submit))
(is (str/ends-with? (e/get-url *driver*) "?login=1&password=2&message=3"))
;; Test with vector form
(e/fill-multi *driver*
[:simple-input 4
:simple-password 5
:simple-textarea 6])
(wait-url-change (e/click *driver* :simple-submit))
(wait-url-change #"login" (e/click *driver* :simple-submit))
(is (str/ends-with? (e/get-url *driver*) "?login=4&password=5&message=6")))
(testing "fill-multi bad inputs"
(is (thrown+? [:type :etaoin/argument]
Expand All @@ -236,14 +238,14 @@
{:simple-input "login"
:simple-password "123"
:simple-textarea "text"})
(wait-url-change (e/click *driver* :simple-submit))
(wait-url-change #"login" (e/click *driver* :simple-submit))
(is (str/ends-with? (e/get-url *driver*) "?login=login&password=123&message=text"))
;; Test with vector form
(e/fill-human-multi *driver*
[:simple-input "login2"
:simple-password "456"
:simple-textarea "text2"])
(wait-url-change (e/click *driver* :simple-submit))
(wait-url-change #"login" (e/click *driver* :simple-submit))
(is (str/ends-with? (e/get-url *driver*) "?login=login2&password=456&message=text2")))
(testing "fill-human-multi bad inputs"
(is (thrown+? [:type :etaoin/argument]
Expand All @@ -254,7 +256,7 @@
(e/fill-multi *driver* [:vector :with :odd :length :is :not :allowed]))))
(testing "fill multiple vars"
(e/fill *driver* :simple-input 1 "test" 2 \space \A)
(wait-url-change (e/click *driver* :simple-submit))
(wait-url-change #"login" (e/click *driver* :simple-submit))
(is (str/ends-with? (e/get-url *driver*) "?login=1test2+A&password=&message=")))
(testing "fill active"
(e/click *driver* :simple-input)
Expand All @@ -263,7 +265,7 @@
(e/fill-active *driver* "MyPassword")
(e/click *driver* :simple-textarea)
(e/fill-active *driver* "Some text")
(wait-url-change (e/click *driver* :simple-submit))
(wait-url-change #"login" (e/click *driver* :simple-submit))
(is (str/ends-with? (e/get-url *driver*)
"?login=MyLogin&password=MyPassword&message=Some+text")))
(testing "fill active human"
Expand All @@ -273,7 +275,7 @@
(e/fill-human-active *driver* "MyPassword2")
(e/click *driver* :simple-textarea)
(e/fill-human-active *driver* "Some text 2")
(wait-url-change (e/click *driver* :simple-submit))
(wait-url-change #"login" (e/click *driver* :simple-submit))
(is (str/ends-with? (e/get-url *driver*)
"?login=MyLogin2&password=MyPassword2&message=Some+text+2"))))

Expand Down Expand Up @@ -312,7 +314,7 @@
(testing "simple clear"
(e/fill *driver* {:id :simple-input} "test")
(e/clear *driver* {:id :simple-input})
(wait-url-change (e/click *driver* {:id :simple-submit}))
(wait-url-change #"login" (e/click *driver* {:id :simple-submit}))
(is (str/ends-with? (e/get-url *driver*) "?login=&password=&message=")))

(testing "multiple clear"
Expand All @@ -329,7 +331,7 @@
:simple-input
:simple-password
:simple-textarea)
(wait-url-change (e/click *driver* {:id :simple-submit}))
(wait-url-change #"login" (e/click *driver* {:id :simple-submit}))
(is (str/ends-with? (e/get-url *driver*) "?login=&password=&message="))))

(deftest test-enabled
Expand Down Expand Up @@ -1140,7 +1142,7 @@
(e/add-pointer-click-el textarea)
e/add-pause
(e/add-pointer-click-el submit))]
(wait-url-change
(wait-url-change #"login"
(e/perform-actions *driver* keyboard mouse))
(is (str/ends-with? (e/get-url *driver*) "?login=1&password=2&message=3")))))

Expand Down

0 comments on commit 3b1e29c

Please sign in to comment.