How to capture Screenshots in C# using Selenium Web driver


Program Syntax:

Pre-requisites:

Step 1: 
Import the below in required test class:
using OpenQA.Selenium;
using ImageFormat = System.Drawing.Imaging.ImageFormat;

Step 2: 
Create a folder to save all screenshots in the system and provide the same system path in the below test code.

Test Syntax:

public void getScreenShot(IWebDriver driver, string testCaseName)
{         
Screenshot image = ((ITakesScreenshot)driver).GetScreenshot();
image.SaveAsFile(string.Format("C:\\<SystemPath>\\{0}.Png", getcurrentTime()+"_"+ testCaseName), ScreenshotImageFormat.Png);
}


Copyright © 2017 qatoolsguide.blogspot.com || ALL RIGHTS RESERVED