Skip to main content

How to take the Screenshot in Selenium WebDriver?


If we want to take the screenshot then we have to convert our WebDriver object into the screenshot object. we need to change the behavior of the drive to take the screenshot . We can do it by casting




First we cast the driver object into the Screenshot object and store the screenshot into the File object

File src= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

Then we need to store the screenshot from file to the local directory. For this we need to Transfer file to local directory by using FileUtils.

FileUtils.copyFile(src,new File("C:\\Users\\admin\\screenshot.png"));

problem you can face while running above 2 lines of code

1) May be possible your java didn't support the FileUtils so you need to add the jar into your java Build path

below is the URL to download the jar


FileUtils, Jar, Jar download, Selenium WebDriver, Automation Testing




2) Second if you are storing the screenshot directly in C driver then you will get an error of access denied, so you can store the file in above mention path which is your own name folder.

Comments

Popular posts from this blog

What is API?

In general way, API (Application Programming Interface) is the intermediate software which is useful for two applications to communicate. API is the tool which is used for interaction of two applications. If developer developing any software which have multiple blocks (Modules) than developer use APIs to put them together.

Smoke Testing

In Smoke Testing, Testing team check the key feature or key bugs of the software. Smoke testing ensure that critical functionality of the software is working fine.If key features are not working then it is no needed to test the overall functionality because it is just waste of time. In Smoke Testing, test team check the basic feature of the software and if basic feature is not working it means software is broken very badly and further testing is unnecessary. If Smoke Testing failed then it is declared that build is unstable and revert back to developer team until smoke test is pass.