简体   繁体   中英

Coypu screenshot

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;

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM