Book Image

Learning Selenium Testing Tools - Third Edition

Book Image

Learning Selenium Testing Tools - Third Edition

Overview of this book

Table of Contents (22 chapters)
Learning Selenium Testing Tools Third Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Capturing screenshots


A lot of times, our Selenium remote control browsers run on different machines than the machine that performs tests. This is because you, as a developer or tester, need a mechanism to have a screenshot of what an error looks like when the test fails. The screenshots that are captured are saved in the PNG format.

Unfortunately, capturing screenshots in Selenium is limited to popular 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 that there will be no need to change your tests.

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

import static openqa.selenium...