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

Why Jmeter is best option for Performance Testing?

There are multiple tools in market for performance testing of any software but Jmeter is the best solution among all of them due to some reason listed below 1) Jmeter is the open source application so users who use this application will not to pay anything. 2) You can use Jmeter for performance of any web application,  Databases and Web Services (REST and SOAP APIs). 3) Jmeter have the user friendly UI component so it is very easy to use. 4) Jmeter can be used to simulate to put maximum number of concurrent users on a server, network or object to test its strength or to analyze overall performance under different load types. 5) Jmeter also use for functional testing for static( JavaScript and HTML) and dynamic( JSP, Servlets and AJAX) resources. 6) Jmeter provides Verity of graphical representations for performance report so it is easy to understand.

Structural Testing

Structural Testing is the type of testing in which user should have the knowledge of the code because in this testing user need to check the structure of the system. Structural Testing is White Box Testing.