Skip to content

Commit

Permalink
Added support for customizing images for failure screenshots #224
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Nov 19, 2015
1 parent 8efd877 commit 0f78d18
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ let coverage (url : 'a) =
on nonMutableInnerUrl
selectors |> List.iter(fun cssSelector -> swallowedJs (script cssSelector))
let p = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"canopy\")
let f = DateTime.Now.ToString("MMM-d_HH-mm-ss-fff")
let f = sprintf "Coverage_%s" (DateTime.Now.ToString("MMM-d_HH-mm-ss-fff"))
let ss = screenshot p f
reporter.coverage nonMutableInnerUrl ss

Expand Down
1 change: 1 addition & 0 deletions src/canopy/configuration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let folderByOSType =
//runner related
let failFast = ref false
let mutable failScreenshotPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\canopy\"
let mutable failScreenshotFileName = fun (test : types.Test) (suite: types.suite) -> DateTime.Now.ToString("MMM-d_HH-mm-ss-fff")

let mutable chromeDir = folderByOSType
let mutable ieDir = folderByOSType
Expand Down
14 changes: 7 additions & 7 deletions src/canopy/runner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,29 @@ let skip id =
skippedCount <- skippedCount + 1
reporter.skip id

let fail (ex : Exception) id =
let fail (ex : Exception) (test : Test) (suite : suite) =
if skipAllTestsOnFailure = true || skipRemainingTestsInContextOnFailure = true then skipNextTest <- true
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 f = configuration.failScreenshotFileName test suite
if failureScreenshotsEnabled = true then
let ss = screenshot configuration.failScreenshotPath f
reporter.fail ex id ss
else reporter.fail ex id Array.empty<byte>
reporter.fail ex test.Id ss
else reporter.fail ex test.Id Array.empty<byte>
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 Array.empty
reporter.fail ex test.Id Array.empty
let safelyGetUrl () = if browser = null then "no browser = no url" else browser.Url

let failSuite (ex: Exception) (suite : suite) =
let reportFailedTest (ex: Exception) (test : Test) =
reporter.testStart test.Id
fail ex test.Id <| safelyGetUrl()
fail ex test suite <| safelyGetUrl()
reporter.testEnd test.Id

// tests are in reverse order and have to be reversed first
Expand Down Expand Up @@ -122,7 +122,7 @@ let run () =
pass()
with
| ex when failureMessage <> null && failureMessage = ex.Message -> pass()
| ex -> fail ex test.Id <| safelyGetUrl()
| ex -> fail ex test suite <| safelyGetUrl()

reporter.testEnd test.Id

Expand Down
7 changes: 7 additions & 0 deletions tests/basictests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ runFailedContextsFirst <- true
reporter <- new LiveHtmlReporter(Chrome, configuration.chromeDir) :> IReporter
reporter.setEnvironment "My Machine"

configuration.failScreenshotFileName <-
(fun test suite ->
let suiteContext = if suite.Context = null then "" else suite.Context
let cleanName = test.Description.Replace(' ','_') //etc
let stamp = DateTime.Now.ToString("MMM-d_HH-mm-ss")
sprintf "%s_%s_%s" suiteContext cleanName stamp)

failFast := true

file1.all()
Expand Down

0 comments on commit 0f78d18

Please sign in to comment.