Skip to content

Commit

Permalink
Fix #254 add onpass and onfail
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Apr 5, 2016
1 parent 051f690 commit 6d49eba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/canopy/runner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ let once f = (last suites).Once <- f
let before f = (last suites).Before <- f
let after f = (last suites).After <- f
let lastly f = (last suites).Lastly <- f
let onPass f = (last suites).OnPass <- f
let onFail f = (last suites).OnFail <- f
let context c =
if (last suites).Context = null then
(last suites).Context <- c
Expand Down Expand Up @@ -60,10 +62,11 @@ let mutable contextFailed = false
let mutable failedContexts : string list = []
let mutable failed = false

let pass id =
let pass id (suite : suite) =
passedCount <- passedCount + 1
reporter.pass id

suite.OnPass()

let skip id =
skippedCount <- skippedCount + 1
reporter.skip id
Expand All @@ -85,12 +88,14 @@ let fail (ex : Exception) (test : Test) (suite : suite) autoFail url =
let ss = screenshot configuration.failScreenshotPath f
reporter.fail ex test.Id ss url
else reporter.fail ex test.Id Array.empty<byte> url
suite.OnFail()
with
| 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 test.Id Array.empty url
suite.OnFail()

let safelyGetUrl () = if browser = null then "no browser = no url" else browser.Url

Expand All @@ -115,7 +120,7 @@ let tryTest test suite func =

let private processRunResult suite (test : Test) result =
match result with
| Pass -> pass test.Id
| Pass -> pass test.Id suite
| Fail ex -> fail ex test suite false <| safelyGetUrl()
| Skip -> skip test.Id
| Todo -> reporter.todo test.Id
Expand Down
2 changes: 2 additions & 0 deletions src/canopy/types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ type suite () = class
member val Before = fun () -> () with get, set
member val After = fun () -> () with get, set
member val Lastly = fun () -> () with get, set
member val OnPass = fun () -> () with get, set
member val OnFail = fun () -> () with get, set
member val Tests : Test list = [] with get, set
member val Wips : Test list = [] with get, set
member val Manys : Test list = [] with get, set
Expand Down

0 comments on commit 6d49eba

Please sign in to comment.