4

On the end of a Scenario, I want to take a picture if it has failed. The following code does not work:

[AfterScenario]
public void AfterScenario()
{
    if(ScenarioContext.Current.TestError != null)
    {
     WebBrowser.Driver.CaptureScreenShot(ScenarioContext.Current.ScenarioInfo.Title);
    }
}

I think this may be due to the fact that I start my browser using Coypu (which has selenium wrapped). The driver does not have a 'captureScreenShot' method implemented. So my question is: how can i take a screenshot after a scenario, when i start up my browser using coypu?

The code for starting the browser is the following:

sessionConfiguration.Driver = typeof (SeleniumWebDriver);
sessionConfiguration.Browser = Drivers.Browser.Firefox;
Chris Missal
  • 5,987
  • 3
  • 28
  • 46
Michael
  • 363
  • 5
  • 20

2 Answers2

2

As you say, this is not implemented in Coypu right now. Reason being I have simply never needed to take a screenshot since so far, and no one's asked till now.

To access the native driver (WebDriver in your case) use BrowserSession.Native then you can use WebDriver's GetScreenshot method. This would end up looking something like this (disclaimer: not tested):

var driver = (ITakesScreenshot) coypuBrowserSession.Native;

var screenshot = driver.GetScreenshot();

screenshot.SaveAsFile("c://screenshot.png", System.Drawing.Imaging.ImageFormat.Png);

I've opened an issue for you on github to have this added to Coypu's BrowserWindow API

Furqan Safdar
  • 16,260
  • 13
  • 59
  • 93
  • 3
    The ability to take a screenshot has now been [added to Coypu](https://github.com/featurist/coypu/issues/30) – Ben Smith May 27 '14 at 23:29
0

This is now natively available in Coypu. You can find the documentation here:

https://github.com/featurist/coypu#screenshots

AggieEric
  • 1,189
  • 8
  • 9