diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 546031de..f336b370 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,12 @@ name: Test -on: [push, pull_request] +on: + push: + branches: + - master + pull_request: + branches: + - master jobs: setup: @@ -71,6 +77,30 @@ jobs: if: ${{ matrix.os == 'ubuntu' }} run: sudo apt-get -y install fluxbox + # No longer pre-installed on macOS github action runners + - name: Install Image Magick on macOS + if: ${{ matrix.os == 'macos' && contains(matrix.needs, 'imagemagick') }} + run: brew install imagemagick + + # No longer pre-installed on macOS github action runners + - name: Install Microsoft Edge on macOS + if: ${{ matrix.os == 'macos' && contains(matrix.needs, 'edge') }} + run: | + brew install --cask microsoft-edge + EDGE_VERSION=$(defaults read /Applications/Microsoft\ Edge.app/Contents/Info CFBundleShortVersionString) + DRIVER_URL="https://msedgedriver.azureedge.net/${EDGE_VERSION}/edgedriver_mac64_m1.zip" + curl -o msedgedriver.zip $DRIVER_URL + mkdir $RUNNER_TEMP/edgedriver + unzip msedgedriver.zip -d $RUNNER_TEMP/edgedriver + echo "$RUNNER_TEMP/edgedriver" >> $GITHUB_PATH + + # No longer pre-installed on macOS github action runners + - name: Install Firefox on macOS + if: ${{ matrix.os == 'macos' && contains(matrix.needs, 'firefox') }} + run: | + brew install --cask firefox + brew install geckodriver + - uses: actions/checkout@v4 - name: Clojure deps cache diff --git a/doc/01-user-guide.adoc b/doc/01-user-guide.adoc index ac26a400..1e290284 100644 --- a/doc/01-user-guide.adoc +++ b/doc/01-user-guide.adoc @@ -54,7 +54,7 @@ Etaoin's test suite covers the following OSes and browsers for both Clojure and | - | - -| macOS +| macOS ^1^ | yes | yes | yes @@ -68,7 +68,8 @@ Etaoin's test suite covers the following OSes and browsers for both Clojure and |=== -NOTE: We did once test against PhantomJS, but since work has long ago stopped on this project, we have dropped testing +1. Our GitHub Actions macOS tests run on silicon (aka arm64, aarch64 or M*) hardware +2. We did once test against PhantomJS, but since work has long ago stopped on this project, we have dropped testing == Installation @@ -2097,7 +2098,7 @@ a| Random port when lanching local WebDriver process, else varies by vendor: a| `:webdriver-url` for *WebDriver* process. When: * omitted, creates a new local WebDriver process (unless `:host` was specified). -* specified, attempts to connect to an existing running WebDriver process. +* specified, attempts to connect to an existing running WebDriver process. See <>. diff --git a/script/test_matrix.clj b/script/test_matrix.clj index 34781599..84e75616 100644 --- a/script/test_matrix.clj +++ b/script/test_matrix.clj @@ -15,6 +15,15 @@ (when (= "ubuntu" os) "--launch-virtual-display")] (remove nil?) (string/join " ")) + :needs (case id + "unit" + ["chrome" "firefox"] + + "api" + (conj ["imagemagick"] browser) + + "ide" + [browser]) :desc (->> [id os browser (if (= "jvm" platform) (str "jdk" jdk-version) platform)] @@ -27,14 +36,18 @@ :cmd (if (= "ubuntu" os) "bb test-doc --launch-virtual-display" "bb test-doc") + :needs ["chrome" "firefox"] :desc (str "test-doc " os " jdk" jdk-version)} ) (defn- github-actions-matrix [] - (let [oses ["macos" "ubuntu" "windows"] + (let [os-jdks {"ubuntu" ["8" "11" "17" "21"] + ;; macOS on GitHub Actions is now arm-based and does not include jdk8 + "macos" ["11" "17" "21"] + "windows" ["8" "11" "17" "21"]} + oses (keys os-jdks) ide-browsers ["chrome" "firefox"] api-browsers ["chrome" "firefox" "edge" "safari"] platforms ["jvm" "bb"] - jdk-versions ["8" "11" "17" "21"] default-opts {:jdk-version "21"}] (->> (concat (for [os oses @@ -43,7 +56,8 @@ (for [os oses platform platforms browser ide-browsers] - (test-def (merge default-opts {:os os :id "ide" :platform platform :browser browser}))) + (test-def (merge default-opts + {:os os :id "ide" :platform platform :browser browser}))) (for [os oses platform platforms browser api-browsers @@ -52,12 +66,14 @@ (test-def (merge default-opts {:os os :id "api" :platform platform :browser browser}))) ;; for jdk coverage we don't need to run across all oses and browsers (for [id ["unit" "ide" "api"] - jdk-version jdk-versions + jdk-version (get os-jdks "ubuntu") :when (not= jdk-version (:jdk-version default-opts))] - (test-def {:jdk-version jdk-version :os "ubuntu" :id id :platform "jvm" :browser "firefox"})) + (test-def {:jdk-version jdk-version :os "ubuntu" :id id + :platform "jvm" + :browser (when (not= "unit" id) "firefox")})) (for [os oses] (test-doc (merge default-opts {:os os}))) - (for [jdk-version jdk-versions + (for [jdk-version (get os-jdks "ubuntu") :when (not= jdk-version (:jdk-version default-opts))] (test-doc {:jdk-version jdk-version :os "ubuntu"}))) (sort-by (juxt #(parse-long (:jdk-version %)) :desc)) @@ -91,7 +107,7 @@ (status/line :detail (if (= "json" (:format opts)) (json/generate-string matrix) - (doric/table [:os :jdk-version :cmd :desc] matrix))))))) + (doric/table [:os :jdk-version :cmd :needs :desc] matrix))))))) (main/when-invoked-as-script (apply -main *command-line-args*)) diff --git a/test/etaoin/unit/unit_test.clj b/test/etaoin/unit/unit_test.clj index 8b500763..28f36262 100644 --- a/test/etaoin/unit/unit_test.clj +++ b/test/etaoin/unit/unit_test.clj @@ -3,6 +3,7 @@ [babashka.fs :as fs] [clojure.spec.alpha :as s] [clojure.test :refer [deftest is testing]] + [clojure.tools.logging :as log] [etaoin.api :as e] [etaoin.ide.flow :as ide] [etaoin.ide.impl.spec :as spec] @@ -108,21 +109,35 @@ (deftest test-retry-launch (testing "give up after max tries" - (let [run-calls (atom 0)] + (let [run-calls (atom 0) + warnings-logged (atom []) + ex (ex-info "firefox badness" {})] (with-redefs [etaoin.impl.proc/run (fn [_ _] (swap! run-calls inc) {:some :process}) - e/running? (fn [_] (throw (ex-info "firefox badness" {})))] + e/running? (fn [_] (throw ex )) + log/log* (fn [_logger level _throwable message] + (swap! warnings-logged conj [level message]))] (is (thrown-with-msg? ExceptionInfo #"gave up trying to launch :firefox after 8 tries" (e/with-firefox {:webdriver-failed-launch-retries 7} driver driver))) - (is (= 8 @run-calls))))) + (is (= 8 @run-calls) "run calls") + (is (= [[:warn "unexpected exception occurred launching :firefox, try 1 (of a max of 8)"] + [:warn "unexpected exception occurred launching :firefox, try 2 (of a max of 8)"] + [:warn "unexpected exception occurred launching :firefox, try 3 (of a max of 8)"] + [:warn "unexpected exception occurred launching :firefox, try 4 (of a max of 8)"] + [:warn "unexpected exception occurred launching :firefox, try 5 (of a max of 8)"] + [:warn "unexpected exception occurred launching :firefox, try 6 (of a max of 8)"] + [:warn "unexpected exception occurred launching :firefox, try 7 (of a max of 8)"]] + @warnings-logged) "warnings logged")))) (testing "succeed before max tries" (let [run-calls (atom 0) - succeed-when-calls 3] + succeed-when-calls 3 + warnings-logged (atom []) + ex (ex-info "safari badness" {})] (with-redefs [etaoin.impl.proc/run (fn [_ _] (swap! run-calls inc) @@ -132,8 +147,10 @@ e/delete-session identity e/running? (fn [_] (if (< @run-calls succeed-when-calls) - (throw (ex-info "safari badness" {})) + (throw ex) true)) + log/log* (fn [_logger level _throwable message] + (swap! warnings-logged conj [level message])) util/get-free-port (constantly 12345)] ;; safari driver has a default of 4 retries (e/with-safari driver @@ -146,7 +163,10 @@ :session "session-key" :type :safari, :url "http://127.0.0.1:12345"} driver))) - (is (= succeed-when-calls @run-calls)))))) + (is (= succeed-when-calls @run-calls)) + (is (= [[:warn "unexpected exception occurred launching :safari, try 1 (of a max of 5)"] + [:warn "unexpected exception occurred launching :safari, try 2 (of a max of 5)"]] + @warnings-logged) "warnings logged"))))) (deftest test-actions (let [keyboard (-> (e/make-key-input)