public void AfterMethod() { // inc. class name var fullNameOfTheMethod = NUnit.Framework.TestContext.CurrentContext.Test.FullName; Console.WriteLine("===========>" + fullNameOfTheMethod);//C_Sharp_Selenium_NUnit.Test_Cases.TearDown_ScreenShot.TestMethod // method name only var methodName = NUnit.Framework.TestContext.CurrentContext.Test.Name; Console.WriteLine("===========>" + methodName); //TestMethod // the state of the test execution var state = NUnit.Framework.TestContext.CurrentContext.Result.Outcome; // TestState enum Console.WriteLine("===========>" + state.ToString()); // 1. (Failed:Error) 2. (Passed) if (!(state.ToString() == "Passed")) { OpenQA.Selenium.ITakesScreenshot ts = driver as ITakesScreenshot; Screenshot screenshot = ts.GetScreenshot(); screenshot.SaveAsFile(Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..")) + "\\Screenshot\\" + methodName + ".png", ScreenshotImageFormat.Png); } Thread.Sleep(3000); driver.Close(); driver.Quit(); }
public void demo() { driver.Url = "https://www.google.com"; OpenQA.Selenium.ITakesScreenshot ts = driver as ITakesScreenshot; Screenshot screenshot = ts.GetScreenshot(); screenshot.SaveAsFile(Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..")) + "\\Screenshot\\" + "TestScreensot" + ".png", ScreenshotImageFormat.Png); }
private void TakeScreenshot(string p_path, string p_comment = null) { ITakesScreenshot.GetScreenshot().SaveAsFile(p_path, ScreenshotImageFormat.Png); }