Skip to content

Commit e6739b1

Browse files
committed
ci: fix for safari
It seems that GitHub Actions no longer supports `file:` urls for when using safaridriver. Switch our api tests to hit a local http server instead. A side benefit is that cookie tests for chrome are more realistic in that they actually return cookies.
1 parent 17f2f23 commit e6739b1

16 files changed

+88
-20
lines changed

bb.edn

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
:org.babashka/cli {:coerce {:nses [:symbol]
4848
:patterns [:string]
4949
:vars [:symbol]}}}
50+
test-server {:doc "Static server to support tests (automatically lanched by tests that need it)"
51+
:extra-deps {org.babashka/http-server {:mvn/version "0.1.12"}}
52+
:task test-server/-main}
5053
test:bb {:doc "Runs tests under Babashka [--help]"
5154
:task test/test-bb}
5255
test-doc {:doc "test code blocks in user guide"

doc/01-user-guide.adoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1075,12 +1075,12 @@ An exception will be thrown if the local file is not found.
10751075
(def file-input {:tag :input :type :file})
10761076
10771077
;; upload a file from your system to the first file input
1078-
(def my-file "env/test/resources/html/drag-n-drop/images/document.png")
1078+
(def my-file "env/test/resources/static/drag-n-drop/images/document.png")
10791079
(e/upload-file driver file-input my-file)
10801080
10811081
;; or pass a native Java File object:
10821082
(require '[clojure.java.io :as io])
1083-
(def my-file (io/file "env/test/resources/html/drag-n-drop/images/document.png"))
1083+
(def my-file (io/file "env/test/resources/static/drag-n-drop/images/document.png"))
10841084
(e/upload-file driver file-input my-file)
10851085
----
10861086

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

script/test_server.clj

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
(ns test-server
2+
(:require [babashka.cli :as cli]
3+
[babashka.http-server :as server]
4+
[lread.status-line :as status]))
5+
6+
(def cli-spec {:help {:desc "This usage help" :alias :h}
7+
:port {:ref "<port>"
8+
:desc "Expose server on this port"
9+
:coerce :int
10+
:default 8888
11+
:alias :p}
12+
:dir {:ref "<dir>"
13+
:desc "Serve static assets from this dir"
14+
:default "./env/test/resources/static"
15+
:alias :d}})
16+
17+
(defn- usage-help []
18+
(status/line :head "Usage help")
19+
(status/line :detail (cli/format-opts {:spec cli-spec :order [:port :dir :help]})) )
20+
21+
(defn- usage-fail [msg]
22+
(status/line :error msg)
23+
(usage-help)
24+
(System/exit 1))
25+
26+
(defn -main [& args]
27+
(let [opts (cli/parse-opts args {:spec cli-spec
28+
:restrict true
29+
:error-fn (fn [{:keys [msg]}]
30+
(usage-fail msg))})]
31+
(if (:help opts)
32+
(usage-help)
33+
(do
34+
(status/line :detail "Static dir: %s" (:dir opts))
35+
(server/exec opts)))))

test/etaoin/api_test.clj

+46-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns etaoin.api-test
22
(:require
33
[babashka.fs :as fs]
4+
[babashka.process :as p]
45
[clojure.edn :as edn]
56
[clojure.java.io :as io]
67
[clojure.java.shell :as shell]
@@ -49,9 +50,14 @@
4950

5051
(def ^:dynamic *driver*)
5152

53+
(def test-server-port 8888)
54+
55+
(defn- test-server-url [path]
56+
(format "http://localhost:%d/%s" test-server-port path))
57+
5258
;; tests failed in safari 13.1.1 https://bugs.webkit.org/show_bug.cgi?id=202589 use STP newest
5359
(defn fixture-browsers [f]
54-
(let [url (-> "html/test.html" io/resource str)]
60+
(let [url (test-server-url "test.html")]
5561
(doseq [type drivers
5662
:let [opts (get default-opts type {})]]
5763
(e/with-driver type opts driver
@@ -70,9 +76,16 @@
7076
(println "Testing with browsers:" drivers)
7177
(f))
7278

79+
(defn test-server [f]
80+
(let [proc (p/process "bb test-server")]
81+
(f)
82+
(p/destroy proc)
83+
@proc))
84+
7385
(use-fixtures
7486
:once
75-
report-browsers)
87+
report-browsers
88+
test-server)
7689

7790
(deftest test-visible
7891
(doto *driver*
@@ -268,7 +281,7 @@
268281
(deftest test-url
269282
(doto *driver*
270283
(-> e/get-url
271-
(str/ends-with? "/resources/html/test.html")
284+
(str/ends-with? "/test.html")
272285
is)))
273286

274287
(deftest test-css-props
@@ -409,7 +422,7 @@
409422

410423
(deftest test-drag-n-drop
411424
(is 1)
412-
(let [url (-> "html/drag-n-drop/index.html" io/resource str)
425+
(let [url (test-server-url "drag-n-drop/index.html")
413426
doc {:class :document}
414427
trash {:xpath "//div[contains(@class, 'trash')]"}]
415428
(doto *driver*
@@ -528,30 +541,43 @@
528541
:path "/"
529542
:name "cookie2"}]))))
530543
(e/when-chrome *driver*
531-
(is (= cookies [])))
544+
(is (= cookies [{:domain "localhost"
545+
:httpOnly false
546+
:name "cookie2"
547+
:path "/"
548+
:sameSite "Lax"
549+
:secure false
550+
:value "test2"}
551+
{:domain "localhost"
552+
:httpOnly false
553+
:name "cookie1"
554+
:path "/"
555+
:sameSite "Lax"
556+
:secure false
557+
:value "test1"}])))
532558
(e/when-firefox *driver*
533559
;; Firefox Webdriver added sameSite, we'll ignore it for now
534560
(let [cookies (map #(dissoc % :sameSite) cookies)]
535561
(is (= cookies [{:name "cookie1",
536562
:value "test1",
537563
:path "/",
538-
:domain "",
564+
:domain "localhost",
539565
:secure false,
540566
:httpOnly false}
541567
{:name "cookie2",
542568
:value "test2",
543569
:path "/",
544-
:domain "",
570+
:domain "localhost",
545571
:secure false,
546572
:httpOnly false}]))))
547573
(e/when-phantom *driver*
548-
(is (= cookies [{:domain "",
574+
(is (= cookies [{:domain "localhost",
549575
:httponly false,
550576
:name "cookie2",
551577
:path "/",
552578
:secure false,
553579
:value "test2"}
554-
{:domain "",
580+
{:domain "localhost",
555581
:httponly false,
556582
:name "cookie1",
557583
:path "/",
@@ -570,15 +596,22 @@
570596
:path "/"
571597
:name "cookie2"}))))
572598
(e/when-chrome *driver*
573-
(is (nil? cookie)))
599+
(is (= cookie
600+
{:domain "localhost"
601+
:httpOnly false
602+
:name "cookie2"
603+
:path "/"
604+
:sameSite "Lax"
605+
:secure false
606+
:value "test2"})))
574607
(e/when-firefox *driver*
575608
;; Firefox Webdriver added sameSite, we'll ignore it for now
576609
(let [cookie (dissoc cookie :sameSite)]
577610
(is (= cookie
578611
{:name "cookie2"
579612
:value "test2"
580613
:path "/"
581-
:domain ""
614+
:domain "localhost"
582615
:secure false
583616
:httpOnly false}))))
584617
(e/when-phantom *driver*
@@ -653,10 +686,7 @@
653686
:bar [true nil "Hello"]})))))
654687

655688
(deftest test-add-script
656-
(let [js-url (-> "js/inject.js" io/resource
657-
fs/file .toURI .toURL ;; little extra dance here for bb on Windows,
658-
;; otherwise slash after file: is ommitted and therefore invalid
659-
str)]
689+
(let [js-url (test-server-url "js/inject.js")]
660690
(testing "adding a script"
661691
(e/add-script *driver* js-url)
662692
(e/wait 1)
@@ -712,7 +742,7 @@
712742
["div" "b" "p" "span"])))))
713743

714744
(deftest test-query-tree
715-
(let [url (-> "html/test2.html" io/resource str)
745+
(let [url (test-server-url "test2.html")
716746
_ (e/go *driver* url)
717747
all-div (e/query-tree *driver* {:tag :div})
718748
all-li (e/query-tree *driver* {:tag :li})

test/etaoin/api_with_driver_test.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
(defn testing-driver? [type]
1616
(some #{type} api-test/drivers))
1717

18-
(def test-page (-> "html/test.html" io/resource str))
18+
(def test-page (-> "static/test.html" io/resource str))
1919
(def my-agent "my agent")
2020

2121
(deftest with-driver-tests

test/etaoin/ide_test.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
(get-default-drivers)))
2929

3030
(defn fixture-browser [f]
31-
(let [base-url (-> "html" io/resource str)
31+
(let [base-url (-> "static" io/resource str)
3232
test-file-path (-> "ide/test.side" io/resource str)]
3333
(doseq [type drivers]
3434
(e/with-driver type {:args ["--no-sandbox"]} driver

0 commit comments

Comments
 (0)