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 switch-window with PhantomJS #264

Merged
merged 3 commits into from
Aug 5, 2020
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
6 changes: 6 additions & 0 deletions resources/html/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ <h3>Display section</h3>
visibility: hidden;
">Test</div>


<h3>Switch Window</h3>
<div>
<a id="switch-window" href="test2.html" target="_blank">Go</a>
</div>

<h3>Enabled section</h3>
<input id="input-disabled" type="text" disabled></input>
<br>
Expand Down
3 changes: 3 additions & 0 deletions resources/html/test2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="" lang="en">

</html>
8 changes: 8 additions & 0 deletions src/etaoin/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
20 changes: 17 additions & 3 deletions test/etaoin/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)")
Expand All @@ -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"))
Expand Down Expand Up @@ -354,6 +354,20 @@
(is (not= width width'))
(is (not= height height'))))))

Copy link
Collaborator

@igrishaev igrishaev Aug 4, 2020

Choose a reason for hiding this comment

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

я как-то не пойму логику этого теста. Ожидал, что будет так:

  • открыть первую страницу, получить заголовок или урл
  • создать новое окно
  • открыть вторую странцу, получить ее заголовок или урл
  • переключиться на первое окно
  • убедиться, что его заголовк или урл равны первому.

чтобы не ходить в сеть, можно создать локальные HTML-файлы test1.html и test2.html

Copy link
Contributor Author

@Uunnamed Uunnamed Aug 4, 2020

Choose a reason for hiding this comment

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

логика такая:

  • браузер открывается с одним единственным окном
  • получаем его id
  • открываем следующее окно
  • получаем id всех окон, и выбираем id нового окна
  • свитчимся и проверяем что действительно переключились

страницы и хождение по урлу это дополнительная проверка скорее, если нужно добавлю

(deftest test-switch-window
(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 (filter #(not= % init-handle) new-handles))
_ (switch-window *driver* new-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*
(let [{:keys [x y]} (get-window-position *driver*)
Expand Down