Capturing Screenshot of a Webpage
Updated: Feb 19
Screenshot can be used for two purpose :
To confirm the end result: We often need to verify the result obtained after each process and these screenshots can be helpful in a quick review of the test cases executed.
Bug report: At times when the script doesn’t find the desired it reports a bug and for the reference, the screenshot of the page is required while logging the bug because it can be possible that the bug is raised because of the discrepancy in the script.
Taking a screenshot in Webdriver can be done in this way:
1. Type caste the Webdriver in the screenshot
TakesScreenshot screenshot =((TakesScreenshot)webdriver);
2. Call the getScreenshotAs function to create an image.
File file = screenshot.getScreenshotAs(OutputType.FILE);
3. Save the image to the desired location