From c2a0c8472d46bf3880a95a847a6f33b47b60c965 Mon Sep 17 00:00:00 2001 From: Uunnamed Date: Tue, 4 Aug 2020 14:52:19 +0300 Subject: [PATCH 1/3] fix switch-window with PhantomJS --- src/etaoin/api.clj | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/etaoin/api.clj b/src/etaoin/api.clj index f86b67c8..663f7930 100644 --- a/src/etaoin/api.clj +++ b/src/etaoin/api.clj @@ -243,6 +243,14 @@ :path [:session (:session @driver) :window] :data {:handle handle}})) +(defmethod switch-window + :phantom + [driver handle] + (execute {:driver driver + :method :post + :path [:session (:session @driver) :window] + :data {:name handle}})) + (defmethod switch-window :chrome [driver handle] From 37e94e955fd5d6452031b8eca5a6b37659f2a867 Mon Sep 17 00:00:00 2001 From: Uunnamed Date: Tue, 4 Aug 2020 15:16:10 +0300 Subject: [PATCH 2/3] update test --- test/etaoin/api_test.clj | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/test/etaoin/api_test.clj b/test/etaoin/api_test.clj index 49943be3..cbcf7be8 100644 --- a/test/etaoin/api_test.clj +++ b/test/etaoin/api_test.clj @@ -43,7 +43,7 @@ {:chrome {:args ["--headless" "--no-sandbox"]} :firefox {:args ["--headless"]} :safari {:path-driver "/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver"} - :edge {:args ["--headless"]}}) + :edge {:args ["--headless"]}}) (def drivers (or (get-drivers-from-env) @@ -222,7 +222,7 @@ (let [result (get-element-csss *driver* {:id :div-css-simple} - :display :background-color "width" "height") + :display :background-color "width" "height") [display background-color width height] result] (is (= display "block")) (is (or (= background-color "rgb(204, 204, 204)") @@ -233,7 +233,7 @@ (let [result (get-element-csss *driver* {:id :div-css-styled} - :display :width :height) + :display :width :height) [display width height] result] (is (= display "block")) (is (= width "333px")) @@ -354,6 +354,15 @@ (is (not= width width')) (is (not= height height')))))) +(deftest test-switch-window + (let [prev-handles (get-window-handles *driver*) + _ (js-execute *driver* "window.open(\"\")") + new-handles (get-window-handles *driver*) + new-handle (first (clojure.set/difference (set new-handles) (set prev-handles))) + _ (switch-window *driver* new-handle) + target-handle (get-window-handle *driver*)] + (is (= new-handle target-handle)))) + (deftest test-maximize (when-not-headless *driver* (let [{:keys [x y]} (get-window-position *driver*) From fd0a7523942d89814778e5ff9543b184258dd0dc Mon Sep 17 00:00:00 2001 From: Uunnamed Date: Wed, 5 Aug 2020 11:56:59 +0300 Subject: [PATCH 3/3] update --- resources/html/test.html | 6 ++++++ resources/html/test2.html | 3 +++ test/etaoin/api_test.clj | 15 ++++++++++----- 3 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 resources/html/test2.html diff --git a/resources/html/test.html b/resources/html/test.html index 2c1fbcc7..e3252a96 100644 --- a/resources/html/test.html +++ b/resources/html/test.html @@ -61,6 +61,12 @@

Display section

visibility: hidden; ">Test + +

Switch Window

+
+ Go +
+

Enabled section


diff --git a/resources/html/test2.html b/resources/html/test2.html new file mode 100644 index 00000000..8da5a529 --- /dev/null +++ b/resources/html/test2.html @@ -0,0 +1,3 @@ + + + diff --git a/test/etaoin/api_test.clj b/test/etaoin/api_test.clj index cbcf7be8..5b8e0a03 100644 --- a/test/etaoin/api_test.clj +++ b/test/etaoin/api_test.clj @@ -355,13 +355,18 @@ (is (not= height height')))))) (deftest test-switch-window - (let [prev-handles (get-window-handles *driver*) - _ (js-execute *driver* "window.open(\"\")") + (let [init-handle (get-window-handle *driver*) + init-url (get-url *driver*) + _ (click *driver* :switch-window) new-handles (get-window-handles *driver*) - new-handle (first (clojure.set/difference (set new-handles) (set prev-handles))) + new-handle (first (filter #(not= % init-handle) new-handles)) _ (switch-window *driver* new-handle) - target-handle (get-window-handle *driver*)] - (is (= new-handle target-handle)))) + target-handle (get-window-handle *driver*) + target-url (get-url *driver*)] + (is (not= init-handle target-handle)) + (is (= 2 (count new-handles))) + (is (= new-handle target-handle)) + (is (not= init-url target-url)))) (deftest test-maximize (when-not-headless *driver*