I have developed complete framework and started tests using BDD & SpecFlow. It was running fine up to extent reports. I'm able to take screenshot but not appended into extent reports html. Can someone please let me know the code for appending screenshots into Specflow extent reports using NUnit test runner.

    public static string Capture(IWebDriver driver, string screenShotName)
        ITakesScreenshot ts = (ITakesScreenshot)driver;
        Screenshot screenshot = ts.GetScreenshot();
        string pth = System.Reflection.Assembly.GetCallingAssembly().CodeBase;
        string finalpth = pth.Substring(0, pth.LastIndexOf("bin")) + "ErrorScreenshots\\" + screenShotName + ".png";
        string localpath = new Uri(finalpth).LocalPath;
        screenshot.SaveAsFile(localpath, ScreenshotImageFormat.Png);
        return localpath;
    public void GetResult()
        var status = NUnit.Framework.TestContext.CurrentContext.Result.Outcome.Status;
        var stackTrace = "<pre>" + NUnit.Framework.TestContext.CurrentContext.Result.StackTrace + "</pre>";
        var errorMessage = NUnit.Framework.TestContext.CurrentContext.Result.Message;

        if (status == TestStatus.Failed)
            string screenShotPath = Capture(DriverContext.Driver, "ScreenShotName");
            Test.Log(LogStatus.Pass, stackTrace + errorMessage);
            Test.Log(LogStatus.Pass, "Snapshot below: " + Test.AddScreenCaptureFromPath(screenShotPath));

0 Answers