From 2c888be181024a31dc9670e87894caf685656243 Mon Sep 17 00:00:00 2001 From: lread Date: Mon, 16 May 2022 19:42:27 -0400 Subject: [PATCH] Proc-test for Windows compensates for scoop Also now closing driver session which closes the window that was always left open at the end of test runs. Fixes #382 --- test/etaoin/proc_test.clj | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/test/etaoin/proc_test.clj b/test/etaoin/proc_test.clj index e8057166..fdc9c092 100644 --- a/test/etaoin/proc_test.clj +++ b/test/etaoin/proc_test.clj @@ -7,16 +7,18 @@ (defn get-count-chromedriver-instances [] - (let [process-count (->> (if proc/windows? - (sh "tasklist") - (sh "sh" "-c" "ps aux")) - :out - str/split-lines - (filter #(str/includes? % "chromedriver")) - count)] - (if proc/windows? - (/ process-count 2) ;; on Windows we seem to have 2 chromedriver.exe instances per launch - process-count))) + (if proc/windows? + (->> (sh "powershell" "-command" "(Get-Process chromedriver -ErrorAction SilentlyContinue).Path") + :out + str/split-lines + (remove #(str/includes? % "\\scoop\\shims\\")) ;; for the scoop users, exclude the shim process + (filter #(str/includes? % "chromedriver")) + count) + (->> (sh "sh" "-c" "ps aux") + :out + str/split-lines + (filter #(str/includes? % "chromedriver")) + count))) (deftest test-prevent-process-fork (testing "certain driver port" @@ -40,6 +42,7 @@ (let [port 9999 process (proc/run ["chromedriver" (format "--port=%d" port)]) _ (wait-running {:port port :host "localhost"}) - _driver (chrome {:host "localhost" :port port :args ["--no-sandbox"]})] + driver (chrome {:host "localhost" :port port :args ["--no-sandbox"]})] (is (= 1 (get-count-chromedriver-instances))) + (quit driver) (proc/kill process))))