Friday, 23 August 2019

Automation Selenium Take a Screen Shot

 public void TakeScreenshot(string fileName, string screenshotPath = null, IWebDriver driver = null)
        {
            Screenshot s = ((ITakesScreenshot)driver).GetScreenshot();//driver = new ChromeDriver();
            var path = @"C:\Ashutosh";

            if (!string.IsNullOrEmpty(screenshotPath))
            {
                path = screenshotPath;
            }

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            s.SaveAsFile(Path.Combine(screenshotPath, fileName + DateTime.Now.ToString("MM-dd-yyyy-HHmmss")), ScreenshotImageFormat.Png);
        }

No comments:

Post a Comment