Friday, July 28, 2017

How take screen shots in Selenium WebDriver?

Screen shots are important to have in the results analysis of test cases. By looking at the captured screen shots we can tell what went wrong or what could be reason for a test case failure.

Selenium WebDriver provides TaskesScreenShot interface to capture the screen shots. This interface is available under package import org.openqa.selenium.TakesScreenshot.

The below test script explains how to capture the screen shot when a test case is failed. The below script launches Gmail login page and tries to enter the username to Email or Phone filed with an invalid id. Since there is no element with the given id on the page it's throws an exception. In the exception block captureScreenShot() method will be called to take the screen shot.

Note: Using TakesScreenshot inSelenium WebDriver we can capture only visible area. What if we want to capture entire page? or What if we want capture particular WebElement as screen shots? We will see that in the next post.

1 comment:

  1. Thanks for providing the information . The articles in your blog helped me a lot for improving the knowledge on the subject. Also check my small collection on this at selenium Online Training Hyderabad blog


Selenium4: Working with two parallel windows in Selenium Automation

A new method newWindow() is introduced in Selenium 4 (Alpha). Using this method we can open a new tab or new window from the current window...