WatiN Integration into MbUnitGallio Reports

One of the cool items I didn’t mentioned in my announcement post is that we now have the ability to integrate screenshots from a WatiN test into the reports.

Here we have a simple test which searches for MbUnit on Google and then asserts to check that NUnit is mentioned on the page (this fails).

public void DemoCaptureOnFailure()
    using (Log.BeginSection(“Go to Google, enter MbUnit as a search term and click I’m Feeling Lucky”))


    // Of course this is ridiculous, we’ll be on the MbUnit homepage…
    Assert.IsTrue(ie.ContainsText(“NUnit”), “Expected to find NUnit on the page.”);

Normally, it would be hard to find out what was actually on the webpage at that point to see why the test decided to fail. In the tear down method, there is a check if the test passed or failed, if it failed then it takes a snapshot and includes it in the report.

public void DisposeBrowser()
    if (Context.CurrentContext.Outcome == TestOutcome.Failed)
        Snapshot(“Final screen when failure occurred.”, LogStreamNames.Failures);

    if (ie != null)

When you view the report, on the test that failed you can see that the screenshot of the webpage has been included.  This will make debugging the error a lot easier, making the tests more useful.


I think this is a great feature, well done to Jeff and the team for implementing this.

Technorati Tags: ,

5 thoughts on “WatiN Integration into MbUnitGallio Reports”

  1. I’ve installed both MbUnit and Gallio: can you tell me what dll’s to reference and what namespaces I need to include so I can gain access to these object?

    Thank you very much.

  2. The sample code can be accessed from the MbUnit source tree.


    Code for the snapshot is this:

    private void Snapshot(string caption)
    Snapshot(caption, Log.Default);

    private void Snapshot(string caption, LogStreamWriter logStreamWriter)
    using (logStreamWriter.BeginSection(caption))
    logStreamWriter.WriteLine(“Url: {0}”, ie.Url);
    logStreamWriter.EmbedImage(null, new CaptureWebPage(ie).CaptureWebPageImage(false, false, 100));

    private class WatiNStreamLogger : ILogWriter
    public void LogAction(string message)

    Hope this helps.


Leave a Reply

Your email address will not be published. Required fields are marked *