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

    ReplyDelete

Katalon 08: Integration of HP ALM with Katalon Studio

In this post, this post we discuss about integration of  HP ALM with Katalon Studio. If we can integrate HP ALM with Katalon we can update ...