How to take Screenshots Using Selenium WebDriver
Posted By : Sandeep Rathor | 02-Dec-2016

If We are using Selenium WebDriver to Automate our Software Web Application then sometime there is need to Capture the Screenshots using Selenium scripts because sometime we have to execute very large number of test cases and in these some test cases are fail so thats's why we need to check that why this test cases has failed.
But before writing the Selenium script you have to add some special liberaries to take screenshot these are:-
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.testng.annotations.Test;
This will help you in Execute the test cases and debug the code in more better way to next time. Here are some basic commands use to write the selenium scripts for capturing the screenshots
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
You can change the file path and name where you want to share
FileUtils.copyFile(scrFile, new File("D:\\screenshot.png"));
THANKS
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Sandeep Rathor
Sandeep is an experienced QA Engineer with skills in Manual testing, Automation Testing and Performance Testing over both Mobile and Web Application