|
10 | 10 | [etaoin.api :as e]
|
11 | 11 | [etaoin.impl.util :as util]
|
12 | 12 | [etaoin.impl.client :as client]
|
| 13 | + [etaoin.keys :as k] |
13 | 14 | [etaoin.test-report :as test-report]
|
14 | 15 | [slingshot.slingshot :refer [try+]])
|
15 | 16 | (:import [java.net ServerSocket]))
|
|
489 | 490 |
|
490 | 491 | (deftest test-switch-window
|
491 | 492 | (let [init-handle (e/get-window-handle *driver*)
|
492 |
| - init-url (e/get-url *driver*) |
493 |
| - _ (e/click *driver* :switch-window) |
494 |
| - new-handles (e/get-window-handles *driver*) |
495 |
| - new-handle (first (filter #(not= % init-handle) new-handles)) |
496 |
| - _ (e/switch-window *driver* new-handle) |
497 |
| - target-handle (e/get-window-handle *driver*) |
498 |
| - target-url (e/get-url *driver*)] |
499 |
| - (is (not= init-handle target-handle)) |
500 |
| - (is (= 2 (count new-handles))) |
501 |
| - (is (= new-handle target-handle)) |
502 |
| - (is (not= init-url target-url)))) |
| 493 | + init-url (e/get-url *driver*)] |
| 494 | + ;; press enter on link instead of clicking (safaridriver is not great with the click) |
| 495 | + (e/fill *driver* :switch-window k/return) |
| 496 | + (is (= 2 (count (e/get-window-handles *driver*))) "2 windows now exist") |
| 497 | + (let [new-handles (e/get-window-handles *driver*) |
| 498 | + new-handle (first (filter #(not= % init-handle) new-handles)) |
| 499 | + _ (e/switch-window *driver* new-handle) |
| 500 | + target-handle (e/get-window-handle *driver*) |
| 501 | + target-url (e/get-url *driver*)] |
| 502 | + (is (not= init-handle target-handle)) |
| 503 | + (is (= new-handle target-handle)) |
| 504 | + (is (not= init-url target-url))))) |
503 | 505 |
|
504 | 506 | (deftest test-switch-window-next
|
505 |
| - (let [_ (repeat 3 #(e/click *driver* :switch-window)) |
506 |
| - init-handle (e/get-window-handle *driver*) |
507 |
| - _ (repeat 4 #(e/switch-window-next *driver*)) |
508 |
| - target-handle (e/get-window-handle *driver*)] |
509 |
| - (is (= init-handle target-handle)))) |
| 507 | + (let [init-handle (e/get-window-handle *driver*)] |
| 508 | + (doseq [_ (range 3)] |
| 509 | + ;; press enter on link instead of clicking (safaridriver is not great with click) |
| 510 | + (e/fill *driver* :switch-window k/return) |
| 511 | + ;; compensate: safari navigates to target window, others stay at source |
| 512 | + (e/when-safari *driver* |
| 513 | + (e/wait 3) ;; safari seems to need a breather |
| 514 | + (e/switch-window *driver* init-handle))) |
| 515 | + (is (= 4 (count (e/get-window-handles *driver*))) "4 windows now exist") |
| 516 | + (is (= init-handle (e/get-window-handle *driver*)) "on first window") |
| 517 | + (doseq [_ (range 3)] |
| 518 | + (e/switch-window-next *driver*) |
| 519 | + (is (not= init-handle (e/get-window-handle *driver*)) "navigating new windows")) |
| 520 | + (e/switch-window-next *driver*) |
| 521 | + (is (= init-handle (e/get-window-handle *driver*)) "wrapped around to original window"))) |
510 | 522 |
|
511 | 523 | ;; TODO: need refactoring not working for headless & firefox
|
512 | 524 | #_
|
|
781 | 793 | (e/perform-actions *driver* keyboard mouse)
|
782 | 794 | (e/wait 1)
|
783 | 795 | (is (str/ends-with? (e/get-url *driver*) "?login=1&password=2&message=3"))))))
|
| 796 | + |
| 797 | +(comment |
| 798 | + ;; start test server |
| 799 | + (def test-server (p/process {:out :inherit :err :inherit} "bb test-server --port" 9993)) |
| 800 | + (def url (format "http://localhost:%d/%s" 9993 "test.html")) |
| 801 | + |
| 802 | + ;; start your favourite webdriver |
| 803 | + (def driver (e/safari)) |
| 804 | + (def driver (e/firefox)) |
| 805 | + |
| 806 | + ;; mimic test fixture |
| 807 | + (e/go driver url) |
| 808 | + (e/wait-visible driver {:id :document-end}) |
| 809 | + |
| 810 | + ;; cleanup |
| 811 | + (e/quit driver) |
| 812 | + (p/destroy test-server) |
| 813 | + |
| 814 | + :eoc) |
0 commit comments