Skip to content

Commit

Permalink
Deprecate when-predicate and when-not-predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
dgr committed Aug 23, 2024
1 parent 602e0ec commit 78757dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ A release with an intentional breaking changes is marked with:
* 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])
** {issue}644[#644]: Deprecate `when-predicate` and `when-not-predicate` macros. See docstrings for guidance on alternatives. These will may be removed from the API at the next release that contains breaking changes. ({person}dgr[@dgr])

== v1.1.41 [minor breaking] - 2024-08-14 [[v1.1.41]]

Expand Down
34 changes: 19 additions & 15 deletions src/etaoin/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2619,72 +2619,76 @@
;; skip/when driver
;;

(defmacro when-not-predicate
"Executes `body` when `predicate` returns falsy."
(defmacro ^{:deprecated "1.1.42"} when-not-predicate
"Executes `body` when `predicate` returns falsy.
Deprecated: Use `clojure.core/when-not` instead."
[predicate & body]
`(when-not (~predicate)
~@body))

(defmacro when-not-drivers
"Executes `body` when browser `driver` is NOT in `browsers`, ex: `#{:chrome :safari}`"
[browsers driver & body]
`(when-not-predicate #((set ~browsers) (dispatch-driver ~driver)) ~@body))
`(when-not ((set ~browsers) (driver-type ~driver)) ~@body))

(defmacro when-not-chrome
"Executes `body` when browser `driver` is NOT Chrome."
[driver & body]
`(when-not-predicate #(chrome? ~driver) ~@body))
`(when-not (chrome? ~driver) ~@body))

(defmacro when-not-edge
"Executes `body` when browser `driver` is NOT Edge."
[driver & body]
`(when-not-predicate #(edge? ~driver) ~@body))
`(when-not (edge? ~driver) ~@body))

(defmacro when-not-firefox
"Executes `body` when browser `driver` is NOT Firefox."
[driver & body]
`(when-not-predicate #(firefox? ~driver) ~@body))
`(when-not (firefox? ~driver) ~@body))

(defmacro when-not-safari
"Executes `body` when browser `driver` is NOT Safari."
[driver & body]
`(when-not-predicate #(safari? ~driver) ~@body))
`(when-not (safari? ~driver) ~@body))

(defmacro when-not-headless
"Executes `body` when browser `driver` is NOT in headless mode."
[driver & body]
`(when-not-predicate #(headless? ~driver) ~@body))
`(when-not (headless? ~driver) ~@body))

(defmacro ^{:deprecated "1.1.42"} when-predicate
"Executes `body` when `predicate` returns truthy.
(defmacro when-predicate
"Executes `body` when `predicate` returns truthy."
Deprecated: Use `clojure.core/when` instead."
[predicate & body]
`(when (~predicate)
~@body))

(defmacro when-chrome
"Executes `body` when browser `driver` is Chrome."
[driver & body]
`(when-predicate #(chrome? ~driver) ~@body))
`(when (chrome? ~driver) ~@body))

(defmacro when-firefox
"Executes `body` when browser `driver` is Firefox."
[driver & body]
`(when-predicate #(firefox? ~driver) ~@body))
`(when (firefox? ~driver) ~@body))

(defmacro when-edge
"Executes `body` when browser `driver` is Edge."
[driver & body]
`(when-predicate #(edge? ~driver) ~@body))
`(when (edge? ~driver) ~@body))

(defmacro when-safari
"Executes `body` when browser `driver` is Safari."
[driver & body]
`(when-predicate #(safari? ~driver) ~@body))
`(when (safari? ~driver) ~@body))

(defmacro when-headless
"Executes `body` when the `driver` is in headless mode."
[driver & body]
`(when-predicate #(headless? ~driver) ~@body))
`(when (headless? ~driver) ~@body))

;;
;; input
Expand Down

0 comments on commit 78757dd

Please sign in to comment.