From 602e0ecb47a189e3e08a9d796034fed6ed6a575d Mon Sep 17 00:00:00 2001 From: Dave Roberts Date: Thu, 22 Aug 2024 16:42:44 -0500 Subject: [PATCH] Add `driver-type` (#643) * Add driver-type Adds a function named `driver-type` that returns the keyword appropriate for the specified `driver`. * Add test for driver-type * Use driver-type in User Guide, with test * Update CHANGELOG with driver-test * Add driver-type to API namespace TOC for docs --- CHANGELOG.adoc | 1 + doc/01-user-guide.adoc | 2 ++ src/etaoin/api.clj | 10 ++++++++-- test/etaoin/api_test.clj | 3 +++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index afc6acc..9a540d0 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -26,6 +26,7 @@ A release with an intentional breaking changes is marked with: ** {issue}620[#620]: Get stricter when unwrapping elements. ({person}dgr[@dgr]) * Docs ** {issue}559[#559]: Deprecate use of `:active` with `query` and other APIs that use `query` under the hood. ({person}dgr[@dgr]) +** {issue}642[#642]: Add `driver-type` to retrieve driver type keyword. ({person}dgr[@dgr]) == v1.1.41 [minor breaking] - 2024-08-14 [[v1.1.41]] diff --git a/doc/01-user-guide.adoc b/doc/01-user-guide.adoc index f8d74bb..d489cd5 100644 --- a/doc/01-user-guide.adoc +++ b/doc/01-user-guide.adoc @@ -241,6 +241,8 @@ endif::[] ;; Start WebDriver for Firefox (def driver (e/firefox)) ;; a Firefox window should appear +(e/driver-type driver) +;; => :firefox ;; let's perform a quick Wiki session diff --git a/src/etaoin/api.clj b/src/etaoin/api.clj index d2311f3..908571f 100644 --- a/src/etaoin/api.clj +++ b/src/etaoin/api.clj @@ -13,7 +13,8 @@ - [[with-edge]] [[with-edge-headless]] [[edge]] [[edge-headless]] [[when-edge]] [[when-not-edge]] - [[with-firefox]] [[with-firefox-headless]] [[firefox]] [[firefox-headless]] [[firefox?]] [[when-firefox]] [[when-not-firefox]] - [[with-safari]] [[safari]] [[safari?]] [[when-safari]] [[when-not-safari]] - - [[driver?]] [[running?]] [[headless?]] [[when-headless]] [[when-not-headless]] + - [[driver?]] [[driver-type]] [[running?]] + - [[headless?]] [[when-headless]] [[when-not-headless]] - [[disconnect-driver]] [[stop-driver]] [[quit]] **WebDriver Lower Level Comms** @@ -2178,10 +2179,15 @@ ;; (defn driver? - "Return true if `driver` is of `type` (e.g. on of: `:chrome`, `:edge`, `:firefox`, `:safari`)" + "Return true if `driver` is of `type` (e.g. one of: `:chrome`, `:edge`, `:firefox`, `:safari`)" [driver type] (= (dispatch-driver driver) type)) +(defn driver-type + "Returns the type of driver (e.g., `:chrome`, `:firefox`, `:safari`, or `:edge`)." + [driver] + (dispatch-driver driver)) + (defn chrome? "Returns true if a `driver` is Chrome." [driver] diff --git a/test/etaoin/api_test.clj b/test/etaoin/api_test.clj index 7d54f4d..19c1f99 100644 --- a/test/etaoin/api_test.clj +++ b/test/etaoin/api_test.clj @@ -1078,6 +1078,9 @@ (->> (e/query-all-from-shadow-root *driver* {:id "shadow-root-host"} {:css "span"}) (mapv #(e/get-element-text-el *driver* %))))))) +(deftest test-driver-type + (is (#{:chrome :firefox :safari :edge} (e/driver-type *driver*)))) + (deftest test-timeouts (let [timeouts {:implicit 32134 :script 78921