Taking Snapshots in WebDriver
It will take screenshot of entire page as we do in captureentirepagescreensshot
WebDriver has provided us one interface TakesScreenshot for capturing the screenshot of web application and This interface provides one method names as getScreenshotAs() to capture screenshot in instance of driver.
This getScreenshotAs() method takes argument of type
OutputType.File
or OutputType.BASE64
or Output.BYTES.
File scrnshot= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
OR ((TakesScreenshot)driver).getScreenshotAs(OutputType.BASE64);
OR ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
NOTE: Here in brackets((TakesScreenshot) is not mandatory it is just showing this driver implemented this getScreenshotAs method from “TakesScreenshot” interface
We have taken the screenshot with the help of getScreenshotsAs() method and and now its time to copy this file somewhere in our file system or in our desktop.
For this purpose we further use copyFile() method of the FileUtils class from theorg.apache.commons.io.FileUtils class.
Placing file in file system by using this line
FileUtils.copyFile(scrFile, new File(“e:\\main_page.png”));
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment