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

Add new-window API to expose WebDriver's New Window endpoint #680

Merged
merged 4 commits into from
Oct 2, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
pull_request:
branches:
- master
workflow_dispatch: # for manual triggering
lread marked this conversation as resolved.
Show resolved Hide resolved

jobs:
setup:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ A release with an intentional breaking changes is marked with:
// (adjust these in publish.clj as you see fit)
== Unreleased

* Changes
** {issue}679[#679]: Add `new-window` function that exposes WebDriver's New Window endpoint.

lread marked this conversation as resolved.
Show resolved Hide resolved
== v1.1.42 - 2024-09-27 [[v1.1.42]]

* Changes
Expand Down
23 changes: 22 additions & 1 deletion src/etaoin/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
- [[get-window-size]] [[set-window-size]]
- [[maximize]]
- [[switch-window]] [[switch-window-next]]
- [[close-window]]
- [[new-window]] [[close-window]]

**Frames**
- [[switch-frame]] [[switch-frame-first]] [[switch-frame-parent]] [[switch-frame-top]] [[with-frame]]
Expand Down Expand Up @@ -372,6 +372,27 @@
(recur hs)))]
(switch-window driver next-handle)))

(defn new-window
"Have `driver` create a new window. The `window-type-hint` parameter
must be either `:tab` or `:window` and specifies the type of window
that is desired, if supported by the browser. If successful, return
a map with keys `:handle` indicating the new window handle and
`:type` indicating the type of window that was actually
created (either `:tab` or `:window`).

https://www.w3.org/TR/webdriver2/#dfn-new-window"
[driver window-type-hint]
(if (#{:tab :window} window-type-hint)
(-> (execute {:driver driver
:method :post
:path [:session (:session driver) :window :new]
:data {:type window-type-hint}})
:value
(update :type keyword))
(throw+ {:type :etaoin/argument
:message "Argument `window-type-hint` must be either `:tab` or `:window`."
:window-type-hint window-type-hint})))

(defn close-window
"Have `driver` close current browser window.
On last window close, closes the session.
Expand Down
10 changes: 10 additions & 0 deletions test/etaoin/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,16 @@
(is (not= width width'))
(is (not= height height'))))))

(deftest test-new-window
(is (= 1 (count (e/get-window-handles *driver*))))
(let [initial-window (e/get-window-handle *driver*)
new-windows (for [_ (range 3)]
(-> (e/new-window *driver* :tab)
lread marked this conversation as resolved.
Show resolved Hide resolved
:handle))
windows (into #{initial-window} new-windows)]
(is (= 4 (count (e/get-window-handles *driver*))))
(is (= windows (set (e/get-window-handles *driver*))))))

(deftest test-switch-window
(let [init-handle (e/get-window-handle *driver*)
init-url (e/get-url *driver*)]
Expand Down
Loading