Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(require 'leiningen.exec)
(leiningen.exec/deps '[[enlive/enlive "1.1.4"]])
(require '[net.cgrand.enlive-html :as html])
(defn result-file-loc
"Returns the location of the result files (either provided as the first
command line argument or a default value of 'test/system/results'"
(let [first-cmd-line-arg (second *command-line-args*)]
(if (or
(nil? first-cmd-line-arg)
(= ":headless" first-cmd-line-arg))
;; Default dir
;; user provided dir
(defn read-html-files
"Given a directory, returns a sequence of instances of each .html
file in the directory"
;; Include only files that end with .html
(filter #(and (.isFile %) (.endsWith (.getName %) ".html"))
(file-seq ( dir))))
(defn extract-failed-test-names
"Given an Enlive html-resource of a Selenium result file, returns names of the
failed test cases"
(map html/text
(html/select selenium-html-resource [:tr.status_failed :td :a])))
(defn find-failed-tests
"Given a collection of Selenium test result files, returns the names of the
failed test cases in the result files"
(reduce (fn [all-failed-tests file]
(let [failed-tests
(->> file
(if-not (empty? failed-tests)
(apply conj all-failed-tests failed-tests)
all-failed-tests))) [] files))
(defn run
"Finds and prints the names of failed test cases from the Selenium result
files in the user provided or default directory"
(->> (result-file-loc) (read-html-files) (find-failed-tests))]
(println failed-test-case)))
;; Run when executed from the command line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment