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 pre checks for query fns #262

Merged
merged 1 commit into from
Aug 5, 2020
Merged
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
33 changes: 32 additions & 1 deletion src/etaoin/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@

(defmethod find-element-from* :firefox
[driver el locator term]
{:pre [(some? el)]}
(-> (execute {:driver driver
:method :post
:path [:session (:session @driver) :element el :element]
Expand All @@ -528,6 +529,7 @@

(defmethod find-element-from* :safari
[driver el locator term]
{:pre [(some? el)]}
(-> (execute {:driver driver
:method :post
:path [:session (:session @driver) :element el :element]
Expand All @@ -538,6 +540,7 @@

(defmethod find-element-from* :default
[driver el locator term]
{:pre [(some? el)]}
(-> (execute {:driver driver
:method :post
:path [:session (:session @driver) :element el :element]
Expand All @@ -549,6 +552,7 @@

(defmethod find-elements-from* :default
[driver el locator term]
{:pre [(some? el)]}
(->> (execute {:driver driver
:method :post
:path [:session (:session @driver) :element el :elements]
Expand Down Expand Up @@ -619,12 +623,14 @@
(defn child
"Finds a single element under given root element."
[driver ancestor-el q]
{:pre [(some? ancestor-el)]}
(let [[loc term] (query/expand driver q)]
(find-element-from* driver ancestor-el loc term)))

(defn children
"Finds multiple elements under given root element."
[driver ancestor-el q]
{:pre [(some? ancestor-el)]}
(let [[loc term] (query/expand driver q)]
(find-elements-from* driver ancestor-el loc term)))

Expand Down Expand Up @@ -721,6 +727,7 @@
(defn click-el
"Click on an element having its system id."
[driver el]
{:pre [(some? el)]}
(execute {:driver driver
:method :post
:path [:session (:session @driver) :element el :click]}))
Expand Down Expand Up @@ -752,6 +759,7 @@
(defmethods double-click-el
[:chrome :phantom]
[driver el]
{:pre [(some? el)]}
(execute {:driver driver
:method :post
:path [:session (:session @driver) :element el :doubleclick]}))
Expand Down Expand Up @@ -854,6 +862,7 @@
(defmethods get-element-size-el
[:chrome :edge :phantom]
[driver el]
{:pre [(some? el)]}
(-> (execute {:driver driver
:method :get
:path [:session (:session @driver) :element el :size]})
Expand All @@ -862,6 +871,7 @@

(defmethod get-element-size-el :firefox
[driver el]
{:pre [(some? el)]}
(-> (execute {:driver driver
:method :get
:path [:session (:session @driver) :element el :rect]})
Expand All @@ -870,6 +880,7 @@

(defmethod get-element-size-el :safari
[driver el]
{:pre [(some? el)]}
(-> (execute {:driver driver
:method :get
:path [:session (:session @driver) :element el :rect]})
Expand All @@ -890,6 +901,7 @@
(defmethods get-element-location-el
[:chrome :edge :phantom]
[driver el]
{:pre [(some? el)]}
(-> (execute {:driver driver
:method :get
:path [:session (:session @driver) :element el :location]})
Expand All @@ -898,6 +910,7 @@

(defmethod get-element-location-el :firefox
[driver el]
{:pre [(some? el)]}
(-> (execute {:driver driver
:method :get
:path [:session (:session @driver) :element el :rect]})
Expand All @@ -906,6 +919,7 @@

(defmethod get-element-location-el :safari
[driver el]
{:pre [(some? el)]}
(-> (execute {:driver driver
:method :get
:path [:session (:session @driver) :element el :rect]})
Expand Down Expand Up @@ -971,6 +985,7 @@

(defn- get-element-property-el
[driver el property]
{:pre [(some? el)]}
(:value (execute {:driver driver
:method :get
:path [:session (:session @driver) :element el :property (name property)]})))
Expand Down Expand Up @@ -1006,6 +1021,7 @@

(defn get-element-attr-el
[driver el attr]
{:pre [(some? el)]}
(:value (execute {:driver driver
:method :get
:path [:session (:session @driver) :element el :attribute (name attr)]})))
Expand Down Expand Up @@ -1051,6 +1067,7 @@

(defn- get-element-css-el
[driver el name*]
{:pre [(some? el)]}
(-> (execute {:driver driver
:method :get
:path [:session (:session @driver) :element el :css (name name*)]})
Expand Down Expand Up @@ -1100,6 +1117,7 @@
(defn get-element-inner-html-el
"Returns element's inner text by its identifier."
[driver el]
{:pre [(some? el)]}
(:value (execute {:driver driver
:method :get
:path [:session (:session @driver) :element el :property :innerHTML]})))
Expand All @@ -1120,6 +1138,7 @@
(defn get-element-tag-el
"Returns element's tag name by its identifier."
[driver el]
{:pre [(some? el)]}
(:value (execute {:driver driver
:method :get
:path [:session (:session @driver) :element el :name]})))
Expand All @@ -1132,6 +1151,7 @@
(defn get-element-text-el
"Returns element's inner text by its identifier."
[driver el]
{:pre [(some? el)]}
(:value (execute {:driver driver
:method :get
:path [:session (:session @driver) :element el :text]})))
Expand All @@ -1151,6 +1171,7 @@
(defn- get-element-value-el
"Low level: returns element's value by its identifier."
[driver el]
{:pre [(some? el)]}
(:value (execute {:driver driver
:method :get
:path [:session (:session @driver) :element el :value]})))
Expand Down Expand Up @@ -1877,12 +1898,14 @@

(defmethod displayed-el? :default ;;TODO it's only for jwp
[driver el]
{:pre [(some? el)]}
(:value (execute {:driver driver
:method :get
:path [:session (:session @driver) :element el :displayed]})))

(defmethod displayed-el? :safari
[driver el]
{:pre [(some? el)]}
(cond
(= (get-element-css-el driver el :display)
"none")
Expand All @@ -1906,7 +1929,9 @@
(def ^{:doc "Oppsite to `visible?`."}
invisible? (complement visible?))

(defn enabled-el? [driver el]
(defn enabled-el?
[driver el]
{:pre [(some? el)]}
(:value (execute {:driver driver
:method :get
:path [:session (:session @driver) :element el :enabled]})))
Expand Down Expand Up @@ -1937,6 +1962,7 @@

(defn has-class-el?
[driver el class]
{:pre [(some? el)]}
(let [classes (get-element-attr-el driver el "class")]
(cond
(nil? classes) false
Expand Down Expand Up @@ -2321,6 +2347,7 @@
(defmethod fill-el
:default
[driver el text & more]
{:pre [(some? el)]}
(execute {:driver driver
:method :post
:path [:session (:session @driver) :element el :value]
Expand All @@ -2329,6 +2356,7 @@
(defmethod fill-el
:firefox ;; todo support the old version for :default
[driver el text & more]
{:pre [(some? el)]}
(execute {:driver driver
:method :post
:path [:session (:session @driver) :element el :value]
Expand All @@ -2337,6 +2365,7 @@
(defmethod fill-el
:safari
[driver el text & more]
{:pre [(some? el)]}
(execute {:driver driver
:method :post
:path [:session (:session @driver) :element el :value]
Expand Down Expand Up @@ -2404,6 +2433,7 @@

(defn fill-human-el
[driver el text opt]
{:pre [(some? el)]}
(let [{:keys [mistake-prob pause-max]
:or {mistake-prob 0.1
pause-max 0.2}} opt
Expand Down Expand Up @@ -2450,6 +2480,7 @@
(defn clear-el
"Clears an element by its identifier."
[driver el]
{:pre [(some? el)]}
(execute {:driver driver
:method :post
:path [:session (:session @driver) :element el :clear]}))
Expand Down