-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minimal safari driver logging (#601)
* Minimal safari driver logging Safaridriver logging is relatively odd. It only has debug level logging, only logs to a file, and discovering that file is somewhat tricky. This change adds minimal support to discover and dump safaridriver logs. I'm not sure how many folks bother with safaridriver testing, so this change might be mostly a favour to myself when diagnosing safaridriver issues that arise from time to time. Closes #563 Incidentally fixes #517 * Oh, Windows does not have SIGTERM (or signals) My initial approach to logging termination of our fake-driver was to have it listen for SIGTERM. This works on macOS/Linux but Windows has no facility to listen for termination signals. So instead, we hook into `:post-stop-fns` for something that works for all OSes.
- Loading branch information
Showing
9 changed files
with
342 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
(ns fake-driver | ||
"A fake WebDriver to support testing, adapt as necessary for tests" | ||
(:require [babashka.cli :as cli] | ||
[cheshire.core :as json] | ||
[lread.status-line :as status] | ||
[org.httpkit.server :as server])) | ||
|
||
(def cli-spec {:help {:desc "This usage help" :alias :h} | ||
:port {:ref "<port>" | ||
:desc "Expose server on this port" | ||
:coerce :int | ||
:default 8888 | ||
:alias :p} | ||
:start-server {:ref "<boolean>" | ||
:desc "Start a fake webdriver request handler" | ||
:default true}}) | ||
|
||
(defn- usage-help [] | ||
(status/line :head "Usage help") | ||
(status/line :detail (cli/format-opts {:spec cli-spec :order [:port :sigterm-filename :start-server :help]})) ) | ||
|
||
(defn- usage-fail [msg] | ||
(status/line :error msg) | ||
(usage-help) | ||
(System/exit 1)) | ||
|
||
(defn make-handler [_opts] | ||
(fn handle-request [{:keys [request-method uri] :as _req}] | ||
(cond | ||
(and (= :post request-method) (= "/session" uri)) | ||
{:status 200 | ||
:headers {"Content-Type" "application/json"} | ||
:body (json/generate-string {:sessionId (random-uuid)})} | ||
(and (= :get request-method) (= "/status" uri)) | ||
{:status 200 | ||
:headers {"Content-Type" "application/json"} | ||
:body (json/generate-string {:ready true})} | ||
:else | ||
{:status 404}))) | ||
|
||
(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) | ||
(when (:start-server opts) | ||
(server/run-server (make-handler opts) opts)))) | ||
|
||
@(promise)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.