Capture Multiple Screenshots in Selenium WebDriver

If you have an automated test case which involves testing of continuous application flow, there is always a chance that you want to capture series of screenshots. If you have ever encountered such need and have wondered how it’s done, look no further than MultiScreenShot. A nice little utility to capture multiple screenshots. Not only this. It also lets you take screenshot of individual element and minimize the browser.

In this post, we will see how we can setup this utility with Selenium WebDriver and use it to capture multiple screenshots. We have taken a simple example of About Google page to explain this process. Let’s get into action. Follow below steps to setup and use MultiScreenShot.

  • Download MultiScreenShot JAR file from here.
  • Associate the downloaded JAR file in your Selenium WebDriver project by adding it into Java Build Path.
  • Import below package in your class file.
  • To use MultiScreenShot, you need to create an object of it as shown in below code. It takes 2 arguments. First is a path to save the screenshot and second is a class name. Here, class name is used to create the folder and save the screenshot inside that.
  • Now, you can just add below code to capture screenshots of your tests.
  • Your method code should look like below after performing all above steps.
  • On running this method, MultiScreenShot captures multiple screenshots and stores them in a folder. Below image shows the output of above example.Capture Multiple Screenshots

Apart from taking multiple screenshots, you can also take screenshot of individual element using by using this code.

And minimize the browser using this code.

All in all, a nifty tool to help you in your Selenium tests. Give it a try and let us know how it goes for you.

Comments
  1. Shivaraj
  2. Savitri

Leave a Reply

Your email address will not be published. Required fields are marked *