If you try to run your automated UI tests on the build server, you can quickly run into problems that are quite hard to analyze.
The most common scenario is that one of your assertion like “Then my name should be displayed” fails, because the web driver does not find your name in the resulting page. It works locally, but what’s the problem on the build server? Permission problems? Timing issues? Browser compatibility? Different locale? Web compilation or configuration errors? All of these are potential candidates, but it is hard to find out quickly which one.
We are using the following SpecFlow event binding to trace the content of the current page in case of an error. In many cases from the page content it’s easy to say what the problem was.
[AfterScenario]
public void AfterWebScenario()
{
if (ScenarioContext.Current.TestError != null)
{
Console.WriteLine("Page src for failing test: {0}",
BrowserContext.SeleniumWebDriver.PageSource);
}
//... (if you stop your browser session after
// each scenario, this comes here probably,
// to ensure that the tracing runs before)
}