From dd59ae94432bb7a70511cfea0ceb7bd4ec9e23fe Mon Sep 17 00:00:00 2001 From: Dave Roberts Date: Mon, 30 Sep 2024 10:05:46 -0500 Subject: [PATCH 1/4] Add workflow_dispatch to test.yml --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4959515..ec19157 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,6 +8,7 @@ on: pull_request: branches: - master + workflow_dispatch: # for manual triggering jobs: setup: From b68ee248296495f4acd24c83fbae1546496b2b1a Mon Sep 17 00:00:00 2001 From: Dave Roberts Date: Wed, 2 Oct 2024 10:19:13 -0500 Subject: [PATCH 2/4] Add new-window API to expose WebDriver's New Window endpoint --- CHANGELOG.adoc | 3 +++ src/etaoin/api.clj | 23 ++++++++++++++++++++++- test/etaoin/api_test.clj | 10 ++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 890d95f..2684a9a 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -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. + == v1.1.42 - 2024-09-27 [[v1.1.42]] * Changes diff --git a/src/etaoin/api.clj b/src/etaoin/api.clj index 8daa0bc..add03c4 100644 --- a/src/etaoin/api.clj +++ b/src/etaoin/api.clj @@ -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]] @@ -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. diff --git a/test/etaoin/api_test.clj b/test/etaoin/api_test.clj index 99c7709..753670f 100644 --- a/test/etaoin/api_test.clj +++ b/test/etaoin/api_test.clj @@ -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) + :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*)] From e5ad233845c384d375473dafb87e8d752aafa521 Mon Sep 17 00:00:00 2001 From: Dave Roberts Date: Wed, 2 Oct 2024 12:03:16 -0500 Subject: [PATCH 3/4] Revert "Add workflow_dispatch to test.yml" This reverts commit dd59ae94432bb7a70511cfea0ceb7bd4ec9e23fe. --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ec19157..4959515 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,6 @@ on: pull_request: branches: - master - workflow_dispatch: # for manual triggering jobs: setup: From 0bbd510c0aeec74794653b1bc1dd557d6b993707 Mon Sep 17 00:00:00 2001 From: Dave Roberts Date: Wed, 2 Oct 2024 12:06:38 -0500 Subject: [PATCH 4/4] Add credit in CHANGELOG --- CHANGELOG.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 2684a9a..48e54eb 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -20,7 +20,7 @@ A release with an intentional breaking changes is marked with: == Unreleased * Changes -** {issue}679[#679]: Add `new-window` function that exposes WebDriver's New Window endpoint. +** {issue}679[#679]: Add `new-window` function that exposes WebDriver's New Window endpoint. ({person}dgr[@dgr]) == v1.1.42 - 2024-09-27 [[v1.1.42]]