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 driver-type #643

Merged
merged 5 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 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`)."
dgr marked this conversation as resolved.
Show resolved Hide resolved
[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
Loading