Skip to content

Commit

Permalink
Improve the html reporter to have environment, start date, total run …
Browse files Browse the repository at this point in the history
…time, context run time, and test run time
  • Loading branch information
lefthandedgoat committed Sep 15, 2015
1 parent 9d8a0dd commit 1914ea2
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 15 deletions.
5 changes: 4 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,7 @@

#### 0.9.33 - September 9 2015
* Fix bug were failing tests were marked as passed [Issue #212](https://github.com/lefthandedgoat/canopy/issues/212)
* Make print info displayed in bottom right of page optional, thanks Jeremy Bellows! [Issue #213](https://github.com/lefthandedgoat/canopy/issues/213)
* Make print info displayed in bottom right of page optional, thanks Jeremy Bellows! [Issue #213](https://github.com/lefthandedgoat/canopy/issues/213)

#### 0.9.34 - September 15 2015
* Improved the HTML reporter to have environment, total time, start date, time per context, and time per test
69 changes: 64 additions & 5 deletions docs/files/reporttemplate.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<html lang="en">
<html lang="en">
<head>
<meta charset="utf-8">
<title>canopy test results</title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/js/bootstrap.min.js"></script>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.min.css"
rel="stylesheet">
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.min.css"rel="stylesheet">
<style>
.masthead ul, .masthead li
{
Expand All @@ -25,6 +24,32 @@
{
border-left: 0px solid #dddddd;
}

.black {
margin-left: 5px;
color: black;
}

.well.mini {
min-height: 0px;
margin-bottom: 0px;
padding: 2px;
position: relative;
top: -3px;
}

.well.mini.clear {
background-color: inherit;
border: none;
-webkit-box-shadow: inherit;
-moz-box-shadow: inherit;
box-shadow: inherit;
top: 0px;
}

.test, .context {
padding: 2px 0 6px 0;
}
</style>
</head>
<body>
Expand Down Expand Up @@ -55,6 +80,18 @@
<span id="skipped">0</span>&nbspSkipped
</label>
</a></li>
<li class="pull-right" id="start"><a>
<label>Start:<span class="black"></span>
</label>
</a></li>
<li class="pull-right" id="total"><a>
<label>Total:<span class="black"></span>
</label>
</a></li>
<li class="pull-right hidden" id="environment"><a>
<label>Environment:<span class="black"></span>
</label>
</a></li>
</ul>
</div>
<hr>
Expand All @@ -77,7 +114,7 @@
};

var addContext = function (context) {
$("#contexts").last('tr').append('<tr class="context" data-context="' + context + '"><td>Context: ' + context + '</td></tr>');
$("#contexts").last('tr').append('<tr data-context="' + context + '"><td><div class="context"><span class="mini well clear">Context: ' + context + '</span><span class="pull-right mini well hidden context-time">0m 0s</span></div></td></tr>');
beginContextResults(context);
};

Expand All @@ -90,7 +127,7 @@

var addToContext = function (context, testName) {
var ctx = $('#contexts tr[data-context="' + context + '"]');
ctx.next('tr').find('table').append('<tr><td><div class="test">' + testName + '</div></td></tr>');
ctx.next('tr').find('table').append('<tr><td><div class="test"><span class="mini well clear">' + testName + '</span><span class="pull-right mini well hidden test-time"></span></div></td></tr>');
};

var updateTestInContext = function (context, passFailSkip, image) {
Expand Down Expand Up @@ -135,6 +172,28 @@
ctx.next('tr').find('table').last('tr').find('.test').last().after('<div class="stack"><pre>' + stack + '</pre></div>');
};

var addTimeToTest = function (context, time) {
var ctx = $('#contexts tr[data-context="' + context + '"]');
ctx.next('tr').find('table').last('tr').find('.test').last().find('.test-time').removeClass('hidden').text(time);
};

var addTimeToContext = function (context, time) {
var ctx = $('#contexts tr[data-context="' + context + '"]');
ctx.find('.context-time').removeClass('hidden').text(time);
};

var setTotalTime = function (time) {
$("#total .black").text(time);
};

var setStartTime = function (time) {
$("#start .black").text(time);
};

var setEnvironment = function (environment) {
$("#environment").removeClass('hidden').find(".black").text(environment);
};

var addMessageToTest = function (context, message) {
var ctx = $('#contexts tr[data-context="' + context + '"]');
if(ctx.next('tr').find('table').last('tr').find('.test').last().siblings('pre').length === 0) {
Expand Down
6 changes: 3 additions & 3 deletions src/canopy/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ open System.Reflection
[<assembly: AssemblyTitleAttribute("canopy")>]
[<assembly: AssemblyProductAttribute("canopy")>]
[<assembly: AssemblyDescriptionAttribute("F# web testing framework")>]
[<assembly: AssemblyVersionAttribute("0.9.33")>]
[<assembly: AssemblyFileVersionAttribute("0.9.33")>]
[<assembly: AssemblyVersionAttribute("0.9.34")>]
[<assembly: AssemblyFileVersionAttribute("0.9.34")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] Version = "0.9.33"
let [<Literal>] Version = "0.9.34"
37 changes: 31 additions & 6 deletions src/canopy/reporters.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type IReporter =
abstract member suiteBegin : unit -> unit
abstract member suiteEnd : unit -> unit
abstract member coverage : string -> byte [] -> unit
abstract member setEnvironment : string -> unit

type ConsoleReporter() =
interface IReporter with
Expand Down Expand Up @@ -98,6 +99,8 @@ type ConsoleReporter() =

member this.skip () = ()

member this.setEnvironment env = ()

type TeamCityReporter() =

let flowId = System.Guid.NewGuid().ToString()
Expand Down Expand Up @@ -166,6 +169,8 @@ type TeamCityReporter() =
member this.skip () = ()
member this.setEnvironment env = ()
type LiveHtmlReporter(browser : BrowserStartMode, driverPath : string) =
let consoleReporter : IReporter = new ConsoleReporter() :> IReporter
Expand Down Expand Up @@ -198,10 +203,13 @@ type LiveHtmlReporter(browser : BrowserStartMode, driverPath : string) =
_browser.Manage().Window.Position <- new System.Drawing.Point((maxWidth * 0),0);
do pin()
let mutable context = System.String.Empty;
let mutable test = System.String.Empty;
let mutable context = System.String.Empty
let mutable test = System.String.Empty
let mutable canQuit = false
let mutable contexts : string list = []
let mutable environment = System.String.Empty
let testStopWatch = System.Diagnostics.Stopwatch()
let contextStopWatch = System.Diagnostics.Stopwatch()
new() = LiveHtmlReporter(Firefox, String.Empty)
new(browser : BrowserStartMode) = LiveHtmlReporter(browser, String.Empty)
Expand Down Expand Up @@ -238,16 +246,22 @@ type LiveHtmlReporter(browser : BrowserStartMode, driverPath : string) =
consoleReporter.describe d

member this.contextStart c =
contextStopWatch.Reset()
contextStopWatch.Start()
contexts <- c :: contexts
context <- System.Web.HttpUtility.JavaScriptStringEncode(c)
this.swallowedJS (sprintf "addContext('%s');" context)
this.swallowedJS (sprintf "collapseContextsExcept('%s');" context)
consoleReporter.contextStart c

member this.contextEnd c =
contextStopWatch.Stop()
let ellapsed = contextStopWatch.Elapsed
this.swallowedJS (sprintf "addTimeToContext ('%s', '%im %is');" context ellapsed.Minutes ellapsed.Seconds)
consoleReporter.contextEnd c

member this.summary minutes seconds passed failed =
member this.summary minutes seconds passed failed =
this.swallowedJS (sprintf "setTotalTime ('%im %is');" minutes seconds)
consoleReporter.summary minutes seconds passed failed

member this.write w =
Expand All @@ -258,11 +272,16 @@ type LiveHtmlReporter(browser : BrowserStartMode, driverPath : string) =
consoleReporter.suggestSelectors selector suggestions

member this.testStart id =
testStopWatch.Reset()
testStopWatch.Start()
test <- System.Web.HttpUtility.JavaScriptStringEncode(id)
this.swallowedJS (sprintf "addToContext ('%s', '%s');" context test)
consoleReporter.testStart id

member this.testEnd id = ()
member this.testEnd id =
testStopWatch.Stop()
let ellapsed = testStopWatch.Elapsed
this.swallowedJS (sprintf "addTimeToTest ('%s', '%im %is');" context ellapsed.Minutes ellapsed.Seconds)

member this.quit () =
match this.reportPath with
Expand All @@ -273,7 +292,10 @@ type LiveHtmlReporter(browser : BrowserStartMode, driverPath : string) =

if canQuit then _browser.Quit()

member this.suiteBegin () = _browser.Navigate().GoToUrl(this.reportTemplateUrl)
member this.suiteBegin () =
_browser.Navigate().GoToUrl(this.reportTemplateUrl)
this.swallowedJS (sprintf "setStartTime ('%s');" (String.Format("{0:F}", System.DateTime.Now)))
if environment <> String.Empty then this.swallowedJS (sprintf "setEnvironment ('%s');" environment)

member this.suiteEnd () =
canQuit <- true
Expand All @@ -290,4 +312,7 @@ type LiveHtmlReporter(browser : BrowserStartMode, driverPath : string) =
this.swallowedJS (sprintf "updateTestInContext('%s', 'Todo', '%s');" context "")

member this.skip () =
this.swallowedJS (sprintf "updateTestInContext('%s', 'Skip', '%s');" context "")
this.swallowedJS (sprintf "updateTestInContext('%s', 'Skip', '%s');" context "")

member this.setEnvironment env =
environment <- env
1 change: 1 addition & 0 deletions tests/basictests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ compareTimeout <- 3.0
pageTimeout <- 3.0
runFailedContextsFirst <- true
reporter <- new LiveHtmlReporter(Chrome, configuration.chromeDir) :> IReporter
reporter.setEnvironment "My Machine"

failFast := true

Expand Down

0 comments on commit 1914ea2

Please sign in to comment.