Skip to content

Commit

Permalink
add pre checks for query fns (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uunnamed authored Aug 5, 2020
1 parent ed1d9d8 commit 12f3e96
Showing 1 changed file with 32 additions and 1 deletion.
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

0 comments on commit 12f3e96

Please sign in to comment.