Search code examples
selenium-webdriverteamcitymspec

How do I save a screenshot when an MSpec/Selenium test fails?


I'm using MSpec to drive some automated UI tests using Selenium WebDriver. Much like the examples I found online. I'm having problems getting it to take screenshot when the test fails.

I saw a comment on another issue where it works because they have a ResultSupplementer in the sample web specs. However, ResultSupplementer does not seem to exist in the latest version of Mspec (0.9.1).

Is there a different way to do this in the latest version of mspec? Ultimately, I'm going to generate HTML reports as TeamCity artifacts and include the screenshot on any failing specs.


Solution

  • I've updated the samples for the latest version of MSpec (in short, you need to implement ISupplementSpecificationResults yourself).

    I've also merged the solutions and converted the MVC project to Nancy. You'll find that there's a bit more infrastructure-related code that grew over the last couple of years and works around various things, like

    • status codes 4xx and 5xx logged by IIS Express
    • IIS and Chrome Driver ports bound by other processes
    • page objects access the web driver with a high-level API
    • I use Paket for dependency management because it's far more powerful than plain NuGet

    All that said, you need to run msbuild.exe mspec-samples.sln and then All-Specs.cmd. I've also checked that a TeamCity build creates screenshots.