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 edge support #253

Merged
merged 1 commit into from
Jul 28, 2020
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
24 changes: 22 additions & 2 deletions src/etaoin/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@
dispatch-driver)

(defmethods get-log-types
[:chrome :edge :phantom] ;;TODO only jwp edge not supported
[:chrome :phantom]
[driver]
(:value (execute {:driver driver
:method :get
Expand Down Expand Up @@ -2291,6 +2291,11 @@
[driver & body]
`(when-predicate #(firefox? ~driver) ~@body))

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

(defmacro when-safari
"Executes the body only if the driver is Safari."
[driver & body]
Expand Down Expand Up @@ -3000,6 +3005,7 @@
(partial boot-driver :firefox))

(def edge
"Launches Edge driver. A shortcut for `boot-driver`."
(partial boot-driver :edge))

(def chrome
Expand Down Expand Up @@ -3028,6 +3034,13 @@
([opt]
(boot-driver :firefox (assoc opt :headless true))))

(defn edge-headless
"Launches headless Edge driver. A shortcut for `boot-driver`."
([]
(edge-headless {}))
([opt]
(boot-driver :edge (assoc opt :headless true))))

(defmacro with-driver
"Performs the body within a driver session.

Expand All @@ -3049,7 +3062,7 @@

(with-driver :firefox {} driver
(go driver \"http://example.com\"))
"
"
[type opt bind & body]
`(client/with-pool {}
(let [~bind (boot-driver ~type ~opt)]
Expand Down Expand Up @@ -3106,3 +3119,10 @@
[opt bind & body]
`(with-driver :firefox (assoc ~opt :headless true) ~bind
~@body))

(defmacro with-edge-headless
"Performs the body with headless Edge session. A shortcut for
`with-driver`."
[opt bind & body]
`(with-driver :edge (assoc ~opt :headless true) ~bind
~@body))
12 changes: 10 additions & 2 deletions src/etaoin/driver.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
Safari endpoints
https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/WebDriverEndpointDoc/Commands/Commands.html

Edge capabilities and endpoints
https://docs.microsoft.com/en-us/microsoft-edge/webdriver

JSON Wire protocol (obsolete)
https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol

Expand Down Expand Up @@ -120,7 +123,12 @@
(defmethod options-name
:safari
[driver]
:safariOptions) ;; todo check
:safariOptions)

(defmethod options-name
:edge
[driver]
:edgeOptions)

(defmethod options-name
:opera
Expand Down Expand Up @@ -232,7 +240,7 @@
driver)

(defmethods set-headless
[:chrome :firefox]
[:edge :chrome :firefox]
[driver]
(-> driver
(assoc :headless true)
Expand Down
42 changes: 22 additions & 20 deletions test/etaoin/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
(def default-opts
{:chrome {:args ["--headless" "--no-sandbox"]}
:firefox {:args ["--headless"]}
:safari {:path-driver "/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver"}})
:safari {:path-driver "/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver"}
:edge {:args ["--headless"]}})

(def drivers
(or (get-drivers-from-env)
Expand Down Expand Up @@ -333,14 +334,15 @@
;; monitor, the next two test will fail due to window error.

(deftest test-window-position
(when-not-phantom *driver*
(let [{:keys [x y]} (get-window-position *driver*)]
(is (numeric? x))
(is (numeric? y))
(set-window-position *driver* (+ x 10) (+ y 10))
(let [{x' :x y' :y} (get-window-position *driver*)]
(is (not= x x'))
(is (not= y y'))))))
(when-not-drivers
[:phantom :edge] *driver*
(let [{:keys [x y]} (get-window-position *driver*)]
(is (numeric? x))
(is (numeric? y))
(set-window-position *driver* (+ x 10) (+ y 10))
(let [{x' :x y' :y} (get-window-position *driver*)]
(is (not= x x'))
(is (not= y y'))))))

(deftest test-window-size
(testing "getting size"
Expand All @@ -353,17 +355,16 @@
(is (not= height height'))))))

(deftest test-maximize
(when-not-drivers
[:chrome :firefox :phantom] *driver*
(let [{:keys [x y]} (get-window-position *driver*)
{:keys [width height]} (get-window-size *driver*)]
(maximize *driver*)
(let [{x' :x y' :y} (get-window-position *driver*)
{width' :width height' :height} (get-window-size *driver*)]
(is (not= x x'))
(is (not= y y'))
(is (not= width width'))
(is (not= height height'))))))
(when-not-headless *driver*
(let [{:keys [x y]} (get-window-position *driver*)
{:keys [width height]} (get-window-size *driver*)]
(maximize *driver*)
(let [{x' :x y' :y} (get-window-position *driver*)
{width' :width height' :height} (get-window-size *driver*)]
(is (not= x x'))
(is (not= y y'))
(is (not= width width'))
(is (not= height height'))))))

(deftest test-active-element
(testing "active element"
Expand Down Expand Up @@ -510,6 +511,7 @@
(let [js-url (-> "js/inject.js" io/resource str)]
(testing "adding a script"
(add-script *driver* js-url)
(wait 1)
(let [result (js-execute *driver* "return injected_func();")]
(is (= result "I was injected"))))))

Expand Down