Book Image

Learning Selenium Testing Tools with Python

By : UNMESH GUNDECHA
Book Image

Learning Selenium Testing Tools with Python

By: UNMESH GUNDECHA

Overview of this book

Table of Contents (17 chapters)
Learning Selenium Testing Tools with Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Capturing screenshots of failures


Capturing screenshots during the test run comes very handy when you want to communicate failures to the developers. It also helps in debugging tests or creating evidence of the test run. Selenium WebDriver comes with built-in methods to capture screenshots during the test run. The WebDriver class provides the following methods to capture and save a screenshot:

Method

Description

Argument

Example

Save_screenshot(filename)

This method gets the screenshot of the current window and saves the image to the specified file.

filename: This is the path/name of the file to which the screenshot will be saved

Driver.save_screenshot("homepage.png")

get_screenshot_as_base64()

This method gets the screenshot of the current window as a base64 encoded string, which is useful in embedding images in HTML.

 

driver.get_screenshot_as_base64()

get_screenshot_as_file(filename)

This method gets the screenshot of the current window. It returns False if there...