Saturday, July 29, 2017

AShot() in Selenium 3 for taking full page screenshot?

As discussed in Important notes about Screenshots in Selenium 2 and Selenium 3 we can take only visible area screenshot using TakesScreenshot interface.

Ashot() is a third party utility supported by Selenium WebDriver to capture the screen shots. The below are the features supported by aShot() utility with repect to screenshots:
  • Capturing the entire page
  • Capture the Web Element
  • Prettifying the screenshot
  • Screenshot comparison
  • Several elements comparison
Our focus here is on capturing the entire page and capturing the web element screenshots. For more deatils on aShot() you can refer here.

To take the full page screenshot of a page AShot() scrolls down the page at particular time intervals “scrollTimeOut” till the bottom of the page and takes the screenshot of entire page.

Using shootingStrategy() method Ashot() takes the entire page screenshot. The syntax is:

Here, “scrollTimeOut” time interval. If scrollTimeOut is 1000 ms, AShot() scrolls for every 1000 ms till the bottom to capture the image. You can observe that during script execution.

And the below line of code is to save the screenshot in the desired location.


Let us see now how to implement it.

Step 1: Download AShot () jar file from here and add it to the project.

Step 2: Create a simple test, below is the test that launches ‘Selenium Babu’ blog and takes it's full page screenshot.

Step 3: The screenshot will be saved in the “screenshots” folder in the project directory. The below video shows the execution of the script and how the screenshot is captured.
If "scrollTimeOut" is increased to 1000 ms or 2000 ms, the screen will be scrolled slowly.

8 comments:

  1. Replies
    1. Thanks Sandeep. Glad to hear that, keep visiting :)

      Delete
  2. Hi Venkat,

    I am getting this below error .

    RuntimeException: org.openqa.selenium.WebDriverException: waiting for evaluate.js load failed

    do you an idea how to fix this?

    ReplyDelete
    Replies
    1. Hi Atul,
      aShot uses jQuery by default to find out the elements coordinates.But some drivers have problems with Javascript execution such as OperaDriver. In this case there is another way to find the WebElement's coordinates.

      new AShot()
      .coordsProvider(new WebDriverCoordsProvider()) //find coordinates with WebDriver API
      .takeScreenshot(webDriver, myWebElement);

      Delete
  3. 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
  4. How much amount of time we need to configure in the scroll timeout. Suppose we are giving 1 millisecond time so with that one millisecond it has to take screenshot since for every millisecond the scroll action occurs.so, taking the screenshot of a webpage by that method happens in what amount of time.Is it lest than millisecond or greater than that time/

    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 ...