Skip to content

Commit

Permalink
Add driver-type (#643)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dgr authored Aug 22, 2024
1 parent 70689f4 commit 602e0ec
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]]

Expand Down
2 changes: 2 additions & 0 deletions doc/01-user-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/etaoin/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions test/etaoin/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 602e0ec

Please sign in to comment.