MainMenu

Home Core Java Overview Maven Tutorials

Friday, 13 January 2017

how to Take screen shot in selenium with example



For Video Tutorial : Move on Youtube Channel


Note : Select the playlist as per your need & move with number sequence


How to take screen shot in selenium webdriver?

For Video :- Click Here


Ans: By selenium we can take the screenshot, here is below example , where we navigate to the "home page" of my website "www.way2testing.com", then i will take the screen shot of this page :
First of all, you need to add jar files in your project Download Jars click here

Alternatively, you can also download the jar file from my google driver.

Click here to download jar from drive


download the jar file as shown below :-



Now Add the Jar files in your project
(Right click on project >> Select Build path >> select Configure build path under the Libraries click on Add External Jars now select the Jar files & click on as shown below in image).



Sample code:-
public class Takescreenshot
{
File src;
File outputfile;
WebDriver driver;
@Test
public void screenShot()
{
System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\Complete selenium\\ChromeDriver\\chromedriver.exe");
driver = new ChromeDriver();
driver.navigate().to("http://www.way2testing.com");
driver.manage().window().maximize();
TakesScreenshot ss = (TakesScreenshot)driver; // typecast TakesScreenshot interface to create object
src = ss.getScreenshotAs(OutputType.FILE); //take the screen shot & store in buffer
outputfile = new File("D:\\Selenium\\Screenshot\\w2t.png");//location of my local machine where i will put image file
try
{
FileUtils.copyFile(src, outputfile); //move screen shot file from buffer to local machine
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
Note : ./screenshot/w2t.png" --
screenshot is the name of folder of project & w2t.png is the name of file.

Tags :

Code to take screen shot in selenium

,

Take screen shot in selenium

No comments:

Post a Comment