Capturing screenshots - Selenium

A lot of the time our Selenium remote control browsers will be running on different machines than the machine that starts the tests. This is because you, as a developer or tester, need a mechanism to have a screenshot of what the error looks like when the test failed. Images that are captured are saved in PNG format.

Unfortunately capturing screenshots in Selenium is limited to real browsers such as Mozilla Firefox, Google Chrome, and Internet Explorer. This is because these browsers have libraries that Selenium can use to take screenshots. As more libraries are added to Selenium for different browsers, you will be able to take more screenshots. They will use the same API call so there will be no need to change your tests.

Screenshots capability lives within an interface called TakesScreenshot. We will cast the driver to this and then use the interface to access getScreenshotAs() method. You will also need to import the following library:

import static openqa.selenium.OutputType.*;

Capturing base64 version of images

In this section we are going to have a look at capturing a base64 representation of an image. Base64 is a group of encoding schemes that allow us to represent binary data as ASCII. A common use for them in web applications is to place data URLs as the source for images to save on downloads that the browser has to do when it is parsing the HTML.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Selenium Topics