From f68ce74f716e37720ac49d5f18e29b0d57e0cb87 Mon Sep 17 00:00:00 2001 From: soerennielsen Date: Sat, 17 May 2014 12:13:41 +0200 Subject: [PATCH 1/3] Runner could fail if screenshot timeout Fix for the fail function in the runner. In the case of a misbehaving website that timed out the screenshot function might also timeout as the webdriver may be busy trying to retrieve the html page. Fix for the fail function ensures that the entire test run is not broken because of a single test/page fail. Also made the screenshot save location configurable. --- src/canopy/configuration.fs | 4 +++- src/canopy/runner.fs | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/canopy/configuration.fs b/src/canopy/configuration.fs index 3e82f9c6..7c328bfb 100644 --- a/src/canopy/configuration.fs +++ b/src/canopy/configuration.fs @@ -1,8 +1,10 @@ module canopy.configuration open reporters +open System //runner related let failFast = ref false +let failScheenshotPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\canopy\" let mutable chromeDir = @"c:\" let mutable ieDir = @"c:\" @@ -16,4 +18,4 @@ let mutable reporter : IReporter = new ConsoleReporter() :> IReporter let mutable disableSuggestOtherSelectors = false let mutable autoPinBrowserRightOnLaunch = true let mutable throwIfMoreThanOneElement = false -let mutable configuredFinders = finders.defaultFinders \ No newline at end of file +let mutable configuredFinders = finders.defaultFinders diff --git a/src/canopy/runner.fs b/src/canopy/runner.fs index f8d8f083..a7ae823a 100644 --- a/src/canopy/runner.fs +++ b/src/canopy/runner.fs @@ -5,6 +5,7 @@ open configuration open canopy open reporters open types +open OpenQA.Selenium let rec private last = function | hd :: [] -> hd @@ -47,13 +48,20 @@ let pass () = reporter.pass () let fail (ex : Exception) id = - if failFast = ref true then failed <- true - failedCount <- failedCount + 1 - contextFailed <- true - let p = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\canopy\" - let f = DateTime.Now.ToString("MMM-d_HH-mm-ss-fff") - let ss = screenshot p f - reporter.fail ex id ss + try + if failFast = ref true then failed <- true + failedCount <- failedCount + 1 + contextFailed <- true + let f = DateTime.Now.ToString("MMM-d_HH-mm-ss-fff") + let ss = screenshot configuration.failScheenshotPath f + reporter.fail ex id ss + + with + | :? WebDriverException as failExc -> + //Fail during error report (likely OpenQA.Selenium.WebDriverException.WebDriverTimeoutException ). + // Don't fail the runner itself, but report it. + reporter.write (sprintf "Error during fail reporting: %s" (failExc.ToString())) + reporter.fail ex id null let run () = reporter.suiteBegin() From bd630943c3f5e792facb86b07778c3a8b0a541c3 Mon Sep 17 00:00:00 2001 From: soerennielsen Date: Sat, 17 May 2014 12:16:13 +0200 Subject: [PATCH 2/3] style. --- src/canopy/runner.fs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/canopy/runner.fs b/src/canopy/runner.fs index a7ae823a..28d940f6 100644 --- a/src/canopy/runner.fs +++ b/src/canopy/runner.fs @@ -55,7 +55,6 @@ let fail (ex : Exception) id = let f = DateTime.Now.ToString("MMM-d_HH-mm-ss-fff") let ss = screenshot configuration.failScheenshotPath f reporter.fail ex id ss - with | :? WebDriverException as failExc -> //Fail during error report (likely OpenQA.Selenium.WebDriverException.WebDriverTimeoutException ). From 580489e0110d1e5ee0fad5cbe9192fd91d701e37 Mon Sep 17 00:00:00 2001 From: soerennielsen Date: Sat, 17 May 2014 12:21:59 +0200 Subject: [PATCH 3/3] Spelling mistake. --- src/canopy/configuration.fs | 2 +- src/canopy/runner.fs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/canopy/configuration.fs b/src/canopy/configuration.fs index 7c328bfb..f46d348d 100644 --- a/src/canopy/configuration.fs +++ b/src/canopy/configuration.fs @@ -4,7 +4,7 @@ open System //runner related let failFast = ref false -let failScheenshotPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\canopy\" +let failScreenshotPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\canopy\" let mutable chromeDir = @"c:\" let mutable ieDir = @"c:\" diff --git a/src/canopy/runner.fs b/src/canopy/runner.fs index 28d940f6..b045d4a3 100644 --- a/src/canopy/runner.fs +++ b/src/canopy/runner.fs @@ -53,7 +53,7 @@ let fail (ex : Exception) id = failedCount <- failedCount + 1 contextFailed <- true let f = DateTime.Now.ToString("MMM-d_HH-mm-ss-fff") - let ss = screenshot configuration.failScheenshotPath f + let ss = screenshot configuration.failScreenshotPath f reporter.fail ex id ss with | :? WebDriverException as failExc ->