From 38a9466c313ff0717a87d4a3c5283919be56c9e4 Mon Sep 17 00:00:00 2001 From: Lee Read Date: Sun, 17 Mar 2024 10:46:35 -0400 Subject: [PATCH] ci: fix for safari (#562) It seems that GitHub Actions no longer supports `file:` urls for when using safaridriver. I spent some time trying to coax it to do so but safaridriver is not well documented, so instead of trying to come up with brittle incantations, now hitting a local http test server for api tests instead. Cookie tests were affected by this changed and adjusted/simplified: - browser specific tests consolidated (and edge now included) - turfed phantom test, we no longer support it Fixes #561 --- bb.edn | 5 +- doc/01-user-guide.adoc | 4 +- .../{html => static}/drag-n-drop/example.css | 0 .../drag-n-drop/example.dart.js | 0 .../drag-n-drop/images/README.md | 0 .../drag-n-drop/images/document.png | Bin .../drag-n-drop/images/trash.png | Bin .../{html => static}/drag-n-drop/index.html | 0 env/test/resources/{ => static}/js/inject.js | 0 .../resources/{html => static}/simple.html | 0 env/test/resources/{html => static}/test.html | 0 .../resources/{html => static}/test2.html | 0 script/test_server.clj | 35 ++ test/etaoin/api_test.clj | 154 +++--- test/etaoin/api_with_driver_test.clj | 447 +++++++++--------- test/etaoin/ide_test.clj | 2 +- 16 files changed, 333 insertions(+), 314 deletions(-) rename env/test/resources/{html => static}/drag-n-drop/example.css (100%) rename env/test/resources/{html => static}/drag-n-drop/example.dart.js (100%) rename env/test/resources/{html => static}/drag-n-drop/images/README.md (100%) rename env/test/resources/{html => static}/drag-n-drop/images/document.png (100%) rename env/test/resources/{html => static}/drag-n-drop/images/trash.png (100%) rename env/test/resources/{html => static}/drag-n-drop/index.html (100%) rename env/test/resources/{ => static}/js/inject.js (100%) rename env/test/resources/{html => static}/simple.html (100%) rename env/test/resources/{html => static}/test.html (100%) rename env/test/resources/{html => static}/test2.html (100%) create mode 100644 script/test_server.clj diff --git a/bb.edn b/bb.edn index e6ec7dbc..6da23a45 100644 --- a/bb.edn +++ b/bb.edn @@ -3,7 +3,8 @@ :deps {doric/doric {:mvn/version "0.9.0"} lread/status-line {:git/url "https://github.com/lread/status-line.git" :sha "cf44c15f30ea3867227fa61ceb823e5e942c707f"} - dev.nubank/docopt {:mvn/version "0.6.1-fix7"}} + dev.nubank/docopt {:mvn/version "0.6.1-fix7"} + org.babashka/http-server {:mvn/version "0.1.12"}} :tasks {;; setup :requires ([babashka.classpath :as cp] @@ -47,6 +48,8 @@ :org.babashka/cli {:coerce {:nses [:symbol] :patterns [:string] :vars [:symbol]}}} + test-server {:doc "Static server to support tests (automatically lanched by tests that need it)" + :task test-server/-main} test:bb {:doc "Runs tests under Babashka [--help]" :task test/test-bb} test-doc {:doc "test code blocks in user guide" diff --git a/doc/01-user-guide.adoc b/doc/01-user-guide.adoc index c3d59a98..727188a7 100644 --- a/doc/01-user-guide.adoc +++ b/doc/01-user-guide.adoc @@ -1075,12 +1075,12 @@ An exception will be thrown if the local file is not found. (def file-input {:tag :input :type :file}) ;; upload a file from your system to the first file input -(def my-file "env/test/resources/html/drag-n-drop/images/document.png") +(def my-file "env/test/resources/static/drag-n-drop/images/document.png") (e/upload-file driver file-input my-file) ;; or pass a native Java File object: (require '[clojure.java.io :as io]) -(def my-file (io/file "env/test/resources/html/drag-n-drop/images/document.png")) +(def my-file (io/file "env/test/resources/static/drag-n-drop/images/document.png")) (e/upload-file driver file-input my-file) ---- diff --git a/env/test/resources/html/drag-n-drop/example.css b/env/test/resources/static/drag-n-drop/example.css similarity index 100% rename from env/test/resources/html/drag-n-drop/example.css rename to env/test/resources/static/drag-n-drop/example.css diff --git a/env/test/resources/html/drag-n-drop/example.dart.js b/env/test/resources/static/drag-n-drop/example.dart.js similarity index 100% rename from env/test/resources/html/drag-n-drop/example.dart.js rename to env/test/resources/static/drag-n-drop/example.dart.js diff --git a/env/test/resources/html/drag-n-drop/images/README.md b/env/test/resources/static/drag-n-drop/images/README.md similarity index 100% rename from env/test/resources/html/drag-n-drop/images/README.md rename to env/test/resources/static/drag-n-drop/images/README.md diff --git a/env/test/resources/html/drag-n-drop/images/document.png b/env/test/resources/static/drag-n-drop/images/document.png similarity index 100% rename from env/test/resources/html/drag-n-drop/images/document.png rename to env/test/resources/static/drag-n-drop/images/document.png diff --git a/env/test/resources/html/drag-n-drop/images/trash.png b/env/test/resources/static/drag-n-drop/images/trash.png similarity index 100% rename from env/test/resources/html/drag-n-drop/images/trash.png rename to env/test/resources/static/drag-n-drop/images/trash.png diff --git a/env/test/resources/html/drag-n-drop/index.html b/env/test/resources/static/drag-n-drop/index.html similarity index 100% rename from env/test/resources/html/drag-n-drop/index.html rename to env/test/resources/static/drag-n-drop/index.html diff --git a/env/test/resources/js/inject.js b/env/test/resources/static/js/inject.js similarity index 100% rename from env/test/resources/js/inject.js rename to env/test/resources/static/js/inject.js diff --git a/env/test/resources/html/simple.html b/env/test/resources/static/simple.html similarity index 100% rename from env/test/resources/html/simple.html rename to env/test/resources/static/simple.html diff --git a/env/test/resources/html/test.html b/env/test/resources/static/test.html similarity index 100% rename from env/test/resources/html/test.html rename to env/test/resources/static/test.html diff --git a/env/test/resources/html/test2.html b/env/test/resources/static/test2.html similarity index 100% rename from env/test/resources/html/test2.html rename to env/test/resources/static/test2.html diff --git a/script/test_server.clj b/script/test_server.clj new file mode 100644 index 00000000..1267e6bf --- /dev/null +++ b/script/test_server.clj @@ -0,0 +1,35 @@ +(ns test-server + (:require [babashka.cli :as cli] + [babashka.http-server :as server] + [lread.status-line :as status])) + +(def cli-spec {:help {:desc "This usage help" :alias :h} + :port {:ref "" + :desc "Expose server on this port" + :coerce :int + :default 8888 + :alias :p} + :dir {:ref "" + :desc "Serve static assets from this dir" + :default "./env/test/resources/static" + :alias :d}}) + +(defn- usage-help [] + (status/line :head "Usage help") + (status/line :detail (cli/format-opts {:spec cli-spec :order [:port :dir :help]})) ) + +(defn- usage-fail [msg] + (status/line :error msg) + (usage-help) + (System/exit 1)) + +(defn -main [& args] + (let [opts (cli/parse-opts args {:spec cli-spec + :restrict true + :error-fn (fn [{:keys [msg]}] + (usage-fail msg))})] + (if (:help opts) + (usage-help) + (do + (status/line :detail "Test server static dir: %s" (:dir opts)) + (server/exec opts))))) diff --git a/test/etaoin/api_test.clj b/test/etaoin/api_test.clj index 9aa269cd..ea9d735f 100644 --- a/test/etaoin/api_test.clj +++ b/test/etaoin/api_test.clj @@ -1,6 +1,7 @@ (ns etaoin.api-test (:require [babashka.fs :as fs] + [babashka.process :as p] [clojure.edn :as edn] [clojure.java.io :as io] [clojure.java.shell :as shell] @@ -8,8 +9,10 @@ [clojure.test :refer [deftest is testing use-fixtures]] [etaoin.api :as e] [etaoin.impl.util :as util] + [etaoin.impl.client :as client] [etaoin.test-report :as test-report] - [slingshot.slingshot :refer [try+]])) + [slingshot.slingshot :refer [try+]]) + (:import [java.net ServerSocket])) (defn numeric? [val] (or (instance? Double val) @@ -49,9 +52,18 @@ (def ^:dynamic *driver*) +(defn- find-available-port [] + (with-open [sock (ServerSocket. 0)] + (.getLocalPort sock))) + +(def ^:dynamic *test-server-port* nil) + +(defn test-server-url [path] + (format "http://localhost:%d/%s" *test-server-port* path)) + ;; tests failed in safari 13.1.1 https://bugs.webkit.org/show_bug.cgi?id=202589 use STP newest (defn fixture-browsers [f] - (let [url (-> "html/test.html" io/resource str)] + (let [url (test-server-url "test.html")] (doseq [type drivers :let [opts (get default-opts type {})]] (e/with-driver type opts driver @@ -70,9 +82,31 @@ (println "Testing with browsers:" drivers) (f)) +(defn test-server [f] + (binding [*test-server-port* (find-available-port)] + (let [proc (p/process {:out :inherit :err :inherit} + "bb test-server --port" *test-server-port*)] + (let [deadline (+ (System/currentTimeMillis) 15000) + test-url (test-server-url "test.html") ] + (loop [] + (let [resp (try (client/http-request {:method :get :url test-url}) + (catch Throwable _ :not-ready))] + (when (= :not-ready resp) + (if (< (System/currentTimeMillis) deadline) + (do + (println "- waiting for test-server to be ready at" test-url) + (Thread/sleep 1000) + (recur)) + (throw (ex-info "Timed out waiting for ready test server" {})))))) + (println "Test server ready")) + (f) + (p/destroy proc) + @proc))) + (use-fixtures :once - report-browsers) + report-browsers + test-server) (deftest test-visible (doto *driver* @@ -268,7 +302,7 @@ (deftest test-url (doto *driver* (-> e/get-url - (str/ends-with? "/resources/html/test.html") + (str/ends-with? "/test.html") is))) (deftest test-css-props @@ -409,7 +443,7 @@ (deftest test-drag-n-drop (is 1) - (let [url (-> "html/drag-n-drop/index.html" io/resource str) + (let [url (test-server-url "drag-n-drop/index.html") doc {:class :document} trash {:xpath "//div[contains(@class, 'trash')]"}] (doto *driver* @@ -510,85 +544,32 @@ (deftest test-cookies (testing "getting all cookies" - (let [cookies (e/get-cookies *driver*)] - (e/when-safari *driver* - ;; Safari Webdriver v16.4 added sameSite, we'll ignore it for now - (let [cookies (map #(dissoc % :sameSite) cookies)] - (is (= cookies - [{:domain ".^filecookies^" - :secure false - :httpOnly false - :value "test1" - :path "/" - :name "cookie1"} - {:domain ".^filecookies^" - :secure false - :httpOnly false - :value "test2" - :path "/" - :name "cookie2"}])))) - (e/when-chrome *driver* - (is (= cookies []))) - (e/when-firefox *driver* - ;; Firefox Webdriver added sameSite, we'll ignore it for now - (let [cookies (map #(dissoc % :sameSite) cookies)] - (is (= cookies [{:name "cookie1", - :value "test1", - :path "/", - :domain "", - :secure false, - :httpOnly false} - {:name "cookie2", - :value "test2", - :path "/", - :domain "", - :secure false, - :httpOnly false}])))) - (e/when-phantom *driver* - (is (= cookies [{:domain "", - :httponly false, - :name "cookie2", - :path "/", - :secure false, - :value "test2"} - {:domain "", - :httponly false, - :name "cookie1", - :path "/", - :secure false, - :value "test1"}]))))) + (let [cookies (e/get-cookies *driver*) + sorted-cookies (->> cookies + (map #(dissoc % :sameSite)) ;; varies, maybe we don't care about this one + (sort-by :name) ;; order varies we don't care + )] + (is (= sorted-cookies [{:domain "localhost" + :httpOnly false + :name "cookie1" + :path "/" + :secure false + :value "test1"} + {:domain "localhost" + :httpOnly false + :name "cookie2" + :path "/" + :secure false + :value "test2"}])))) (testing "getting a cookie" - (let [cookie (e/get-cookie *driver* :cookie2)] - (e/when-safari *driver* - ;; Safari Webdriver v16.4 added sameSite, we'll ignore it for now - (let [cookie (dissoc cookie :sameSite)] - (is (= cookie - {:domain ".^filecookies^" - :secure false - :httpOnly false - :value "test2" - :path "/" - :name "cookie2"})))) - (e/when-chrome *driver* - (is (nil? cookie))) - (e/when-firefox *driver* - ;; Firefox Webdriver added sameSite, we'll ignore it for now - (let [cookie (dissoc cookie :sameSite)] - (is (= cookie - {:name "cookie2" - :value "test2" - :path "/" - :domain "" - :secure false - :httpOnly false})))) - (e/when-phantom *driver* - (is (= cookie - {:domain "" - :httponly false - :name "cookie2" - :path "/" - :secure false - :value "test2"}))))) + (let [cookie (e/get-cookie *driver* :cookie2) + cookie (dissoc cookie :sameSite)] + (is (= cookie {:domain "localhost" + :httpOnly false + :name "cookie2" + :path "/" + :secure false + :value "test2"})))) (testing "deleting a cookie" (e/when-not-phantom *driver* @@ -653,10 +634,7 @@ :bar [true nil "Hello"]}))))) (deftest test-add-script - (let [js-url (-> "js/inject.js" io/resource - fs/file .toURI .toURL ;; little extra dance here for bb on Windows, - ;; otherwise slash after file: is ommitted and therefore invalid - str)] + (let [js-url (test-server-url "js/inject.js")] (testing "adding a script" (e/add-script *driver* js-url) (e/wait 1) @@ -712,7 +690,7 @@ ["div" "b" "p" "span"]))))) (deftest test-query-tree - (let [url (-> "html/test2.html" io/resource str) + (let [url (test-server-url "test2.html") _ (e/go *driver* url) all-div (e/query-tree *driver* {:tag :div}) all-li (e/query-tree *driver* {:tag :li}) diff --git a/test/etaoin/api_with_driver_test.clj b/test/etaoin/api_with_driver_test.clj index 5fbcc82c..d6eedeed 100644 --- a/test/etaoin/api_with_driver_test.clj +++ b/test/etaoin/api_with_driver_test.clj @@ -5,8 +5,7 @@ These tests are separate etaoin.api-test because it uses a fixture as part of its strategy. We do reuse the driver selection mechanism from etaoin.api-test tho." - (:require [clojure.java.io :as io] - [clojure.test :refer [deftest is testing]] + (:require [clojure.test :refer [deftest is testing use-fixtures]] [etaoin.api :as e] [etaoin.api2 :as e2] [etaoin.api-test :as api-test] @@ -15,226 +14,230 @@ (defn testing-driver? [type] (some #{type} api-test/drivers)) -(def test-page (-> "html/test.html" io/resource str)) (def my-agent "my agent") +(use-fixtures + :once + api-test/test-server) + (deftest with-driver-tests - (when (testing-driver? :chrome) - (testing "chrome" - (println "testing chrome") - ;; with opts - (is (= my-agent - (e/with-driver :chrome {:user-agent my-agent} driver - (e/get-user-agent driver)) - (e/with-chrome {:user-agent my-agent} driver - (e/get-user-agent driver)) - (e/with-chrome-headless {:user-agent my-agent} driver - (is (= true (e/headless? driver))) - (e/get-user-agent driver)) - (e2/with-chrome [driver {:user-agent my-agent}] - (e/get-user-agent driver)) - (e2/with-chrome-headless [driver {:user-agent my-agent}] - (is (= true (e/headless? driver))) - (e/get-user-agent driver)))) - ;; without opts - (is (= "Webdriver Test Document" - #_{:clj-kondo/ignore [:etaoin/empty-opts]} - (e/with-driver :chrome nil driver - (e/go driver test-page) - (e/get-title driver)) - #_{:clj-kondo/ignore [:etaoin/empty-opts]} - (e/with-driver :chrome {} driver - (e/go driver test-page) - (e/get-title driver)) - (e/with-driver :chrome driver - (e/go driver test-page) - (e/get-title driver)) - - #_{:clj-kondo/ignore [:etaoin/empty-opts]} - (e/with-chrome nil driver - (e/go driver test-page) - (e/get-title driver)) - #_{:clj-kondo/ignore [:etaoin/empty-opts]} - (e/with-chrome {} driver - (e/go driver test-page) - (e/get-title driver)) - (e/with-chrome driver - (e/go driver test-page) - (e/get-title driver)) - - #_{:clj-kondo/ignore [:etaoin/empty-opts]} - (e/with-chrome-headless nil driver - (is (= true (e/headless? driver))) - (e/go driver test-page) - (e/get-title driver)) - #_{:clj-kondo/ignore [:etaoin/empty-opts]} - (e/with-chrome-headless {} driver - (is (= true (e/headless? driver))) - (e/go driver test-page) - (e/get-title driver)) - (e/with-chrome-headless driver - (is (= true (e/headless? driver))) - (e/go driver test-page) - (e/get-title driver)) - - (e2/with-chrome [driver] - (e/go driver test-page) - (e/get-title driver)) - (e2/with-chrome-headless [driver] - (is (= true (e/headless? driver))) - (e/go driver test-page) - (e/get-title driver)))))) - - (when (testing-driver? :firefox) - (testing "firefox" - (println "testing firefox") - ;; with opts - (is (= my-agent - (e/with-driver :firefox {:user-agent my-agent} driver - (e/get-user-agent driver)) - (e/with-firefox {:user-agent my-agent} driver - (e/get-user-agent driver)) - (e/with-firefox-headless {:user-agent my-agent} driver - (is (= true (e/headless? driver))) - (e/get-user-agent driver)) - (e2/with-firefox [driver {:user-agent my-agent}] - (e/get-user-agent driver)) - (e2/with-firefox-headless [driver {:user-agent my-agent}] - (is (= true (e/headless? driver))) - (e/get-user-agent driver)))) - ;; without opts - (is (= "Webdriver Test Document" - (e/with-driver :firefox driver - (e/go driver test-page) - (e/get-title driver)) - - #_{:clj-kondo/ignore [:etaoin/empty-opts]} - (e/with-firefox nil driver - (e/go driver test-page) - (e/get-title driver)) - #_{:clj-kondo/ignore [:etaoin/empty-opts]} - (e/with-firefox {} driver - (e/go driver test-page) - (e/get-title driver)) - (e/with-firefox driver - (e/go driver test-page) - (e/get-title driver)) - - #_{:clj-kondo/ignore [:etaoin/empty-opts]} - (e/with-firefox-headless nil driver - (is (= true (e/headless? driver))) - (e/go driver test-page) - (e/get-title driver)) - #_{:clj-kondo/ignore [:etaoin/empty-opts]} - (e/with-firefox-headless {} driver - (is (= true (e/headless? driver))) - (e/go driver test-page) - (e/get-title driver)) - (e/with-firefox-headless driver - (is (= true (e/headless? driver))) - (e/go driver test-page) - (e/get-title driver)) - - (e2/with-firefox [driver] - (e/go driver test-page) - (e/get-title driver)) - (e2/with-firefox-headless [driver] - (is (= true (e/headless? driver))) - (e/go driver test-page) - (e/get-title driver)))))) - - (when (testing-driver? :edge) - (testing "edge" - (println "testing edge") - ;; with opts - (is (= my-agent - (e/with-driver :edge {:user-agent my-agent} driver - (e/get-user-agent driver)) - (e/with-edge {:user-agent my-agent} driver - (e/get-user-agent driver)) - (e/with-edge-headless {:user-agent my-agent} driver - (is (= true (e/headless? driver))) - (e/get-user-agent driver)) - (e2/with-edge [driver {:user-agent my-agent}] - (e/get-user-agent driver)) - (e2/with-edge-headless [driver {:user-agent my-agent}] - (is (= true (e/headless? driver))) - (e/get-user-agent driver)))) - ;; without opts - (is (= "Webdriver Test Document" - (e/with-driver :edge driver - (e/go driver test-page) - (e/get-title driver)) - - #_{:clj-kondo/ignore [:etaoin/empty-opts]} - (e/with-edge nil driver - (e/go driver test-page) - (e/get-title driver)) - #_{:clj-kondo/ignore [:etaoin/empty-opts]} - (e/with-edge {} driver - (e/go driver test-page) - (e/get-title driver)) - (e/with-edge driver - (e/go driver test-page) - (e/get-title driver)) - - #_{:clj-kondo/ignore [:etaoin/empty-opts]} - (e/with-edge-headless nil driver - (is (= true (e/headless? driver))) - (e/go driver test-page) - (e/get-title driver)) - #_{:clj-kondo/ignore [:etaoin/empty-opts]} - (e/with-edge-headless {} driver - (is (= true (e/headless? driver))) - (e/go driver test-page) - (e/get-title driver)) - (e/with-edge-headless driver - (is (= true (e/headless? driver))) - (e/go driver test-page) - (e/get-title driver)) - - (e2/with-edge [driver] - (e/go driver test-page) - (e/get-title driver)) - (e2/with-edge-headless [driver] - (is (= true (e/headless? driver))) - (e/go driver test-page) - (e/get-title driver)))))) - - (when (testing-driver? :safari) - (testing "safari" - (println "testing safari") - ;; with opts - ;; safari driver does supports neither user agent nor headless - ;; not sure what other safari option is reflected in session... port? - (let [port 9995] - (e/with-driver :safari {:port port} driver - (is (= port (:port driver))) - (is (= true (e/running? driver)))) - (e/with-safari {:port port} driver - (is (= port (:port driver))) - (is (= true (e/running? driver))) ) - (e2/with-safari [driver {:port port}] - (is (= port (:port driver))) - (is (= true (e/running? driver))))) - ;; without opts - (is (= "Webdriver Test Document" - (e/with-driver :safari driver - (e/go driver test-page) - (e/get-title driver)) - - #_{:clj-kondo/ignore [:etaoin/empty-opts]} - (e/with-safari nil driver - (e/go driver test-page) - (e/get-title driver)) - #_{:clj-kondo/ignore [:etaoin/empty-opts]} - (e/with-safari {} driver - (e/go driver test-page) - (e/get-title driver)) - (e/with-safari driver - (e/go driver test-page) - (e/get-title driver)) - - (e2/with-safari [driver] - (e/go driver test-page) - (e/get-title driver))))))) + (let [test-page (api-test/test-server-url "test.html")] + (when (testing-driver? :chrome) + (testing "chrome" + (println "testing chrome") + ;; with opts + (is (= my-agent + (e/with-driver :chrome {:user-agent my-agent} driver + (e/get-user-agent driver)) + (e/with-chrome {:user-agent my-agent} driver + (e/get-user-agent driver)) + (e/with-chrome-headless {:user-agent my-agent} driver + (is (= true (e/headless? driver))) + (e/get-user-agent driver)) + (e2/with-chrome [driver {:user-agent my-agent}] + (e/get-user-agent driver)) + (e2/with-chrome-headless [driver {:user-agent my-agent}] + (is (= true (e/headless? driver))) + (e/get-user-agent driver)))) + ;; without opts + (is (= "Webdriver Test Document" + #_{:clj-kondo/ignore [:etaoin/empty-opts]} + (e/with-driver :chrome nil driver + (e/go driver test-page) + (e/get-title driver)) + #_{:clj-kondo/ignore [:etaoin/empty-opts]} + (e/with-driver :chrome {} driver + (e/go driver test-page) + (e/get-title driver)) + (e/with-driver :chrome driver + (e/go driver test-page) + (e/get-title driver)) + + #_{:clj-kondo/ignore [:etaoin/empty-opts]} + (e/with-chrome nil driver + (e/go driver test-page) + (e/get-title driver)) + #_{:clj-kondo/ignore [:etaoin/empty-opts]} + (e/with-chrome {} driver + (e/go driver test-page) + (e/get-title driver)) + (e/with-chrome driver + (e/go driver test-page) + (e/get-title driver)) + + #_{:clj-kondo/ignore [:etaoin/empty-opts]} + (e/with-chrome-headless nil driver + (is (= true (e/headless? driver))) + (e/go driver test-page) + (e/get-title driver)) + #_{:clj-kondo/ignore [:etaoin/empty-opts]} + (e/with-chrome-headless {} driver + (is (= true (e/headless? driver))) + (e/go driver test-page) + (e/get-title driver)) + (e/with-chrome-headless driver + (is (= true (e/headless? driver))) + (e/go driver test-page) + (e/get-title driver)) + + (e2/with-chrome [driver] + (e/go driver test-page) + (e/get-title driver)) + (e2/with-chrome-headless [driver] + (is (= true (e/headless? driver))) + (e/go driver test-page) + (e/get-title driver)))))) + + (when (testing-driver? :firefox) + (testing "firefox" + (println "testing firefox") + ;; with opts + (is (= my-agent + (e/with-driver :firefox {:user-agent my-agent} driver + (e/get-user-agent driver)) + (e/with-firefox {:user-agent my-agent} driver + (e/get-user-agent driver)) + (e/with-firefox-headless {:user-agent my-agent} driver + (is (= true (e/headless? driver))) + (e/get-user-agent driver)) + (e2/with-firefox [driver {:user-agent my-agent}] + (e/get-user-agent driver)) + (e2/with-firefox-headless [driver {:user-agent my-agent}] + (is (= true (e/headless? driver))) + (e/get-user-agent driver)))) + ;; without opts + (is (= "Webdriver Test Document" + (e/with-driver :firefox driver + (e/go driver test-page) + (e/get-title driver)) + + #_{:clj-kondo/ignore [:etaoin/empty-opts]} + (e/with-firefox nil driver + (e/go driver test-page) + (e/get-title driver)) + #_{:clj-kondo/ignore [:etaoin/empty-opts]} + (e/with-firefox {} driver + (e/go driver test-page) + (e/get-title driver)) + (e/with-firefox driver + (e/go driver test-page) + (e/get-title driver)) + + #_{:clj-kondo/ignore [:etaoin/empty-opts]} + (e/with-firefox-headless nil driver + (is (= true (e/headless? driver))) + (e/go driver test-page) + (e/get-title driver)) + #_{:clj-kondo/ignore [:etaoin/empty-opts]} + (e/with-firefox-headless {} driver + (is (= true (e/headless? driver))) + (e/go driver test-page) + (e/get-title driver)) + (e/with-firefox-headless driver + (is (= true (e/headless? driver))) + (e/go driver test-page) + (e/get-title driver)) + + (e2/with-firefox [driver] + (e/go driver test-page) + (e/get-title driver)) + (e2/with-firefox-headless [driver] + (is (= true (e/headless? driver))) + (e/go driver test-page) + (e/get-title driver)))))) + + (when (testing-driver? :edge) + (testing "edge" + (println "testing edge") + ;; with opts + (is (= my-agent + (e/with-driver :edge {:user-agent my-agent} driver + (e/get-user-agent driver)) + (e/with-edge {:user-agent my-agent} driver + (e/get-user-agent driver)) + (e/with-edge-headless {:user-agent my-agent} driver + (is (= true (e/headless? driver))) + (e/get-user-agent driver)) + (e2/with-edge [driver {:user-agent my-agent}] + (e/get-user-agent driver)) + (e2/with-edge-headless [driver {:user-agent my-agent}] + (is (= true (e/headless? driver))) + (e/get-user-agent driver)))) + ;; without opts + (is (= "Webdriver Test Document" + (e/with-driver :edge driver + (e/go driver test-page) + (e/get-title driver)) + + #_{:clj-kondo/ignore [:etaoin/empty-opts]} + (e/with-edge nil driver + (e/go driver test-page) + (e/get-title driver)) + #_{:clj-kondo/ignore [:etaoin/empty-opts]} + (e/with-edge {} driver + (e/go driver test-page) + (e/get-title driver)) + (e/with-edge driver + (e/go driver test-page) + (e/get-title driver)) + + #_{:clj-kondo/ignore [:etaoin/empty-opts]} + (e/with-edge-headless nil driver + (is (= true (e/headless? driver))) + (e/go driver test-page) + (e/get-title driver)) + #_{:clj-kondo/ignore [:etaoin/empty-opts]} + (e/with-edge-headless {} driver + (is (= true (e/headless? driver))) + (e/go driver test-page) + (e/get-title driver)) + (e/with-edge-headless driver + (is (= true (e/headless? driver))) + (e/go driver test-page) + (e/get-title driver)) + + (e2/with-edge [driver] + (e/go driver test-page) + (e/get-title driver)) + (e2/with-edge-headless [driver] + (is (= true (e/headless? driver))) + (e/go driver test-page) + (e/get-title driver)))))) + + (when (testing-driver? :safari) + (testing "safari" + (println "testing safari") + ;; with opts + ;; safari driver does supports neither user agent nor headless + ;; not sure what other safari option is reflected in session... port? + (let [port 9995] + (e/with-driver :safari {:port port} driver + (is (= port (:port driver))) + (is (= true (e/running? driver)))) + (e/with-safari {:port port} driver + (is (= port (:port driver))) + (is (= true (e/running? driver))) ) + (e2/with-safari [driver {:port port}] + (is (= port (:port driver))) + (is (= true (e/running? driver))))) + ;; without opts + (is (= "Webdriver Test Document" + (e/with-driver :safari driver + (e/go driver test-page) + (e/get-title driver)) + + #_{:clj-kondo/ignore [:etaoin/empty-opts]} + (e/with-safari nil driver + (e/go driver test-page) + (e/get-title driver)) + #_{:clj-kondo/ignore [:etaoin/empty-opts]} + (e/with-safari {} driver + (e/go driver test-page) + (e/get-title driver)) + (e/with-safari driver + (e/go driver test-page) + (e/get-title driver)) + + (e2/with-safari [driver] + (e/go driver test-page) + (e/get-title driver)))))))) diff --git a/test/etaoin/ide_test.clj b/test/etaoin/ide_test.clj index 7ab4753f..4a3a1595 100644 --- a/test/etaoin/ide_test.clj +++ b/test/etaoin/ide_test.clj @@ -28,7 +28,7 @@ (get-default-drivers))) (defn fixture-browser [f] - (let [base-url (-> "html" io/resource str) + (let [base-url (-> "static" io/resource str) test-file-path (-> "ide/test.side" io/resource str)] (doseq [type drivers] (e/with-driver type {:args ["--no-sandbox"]} driver