Taking entire page screenshot using AShot in Katalon Studio


#1

I have made a demo project here:

------

Problem to solve

I wanted to take an screenshot of a Web page. The target page was supposed to have the height over 10,000px.

I tried WebUI.takescreenshot() and found it can only take visual portion; it can not take the image of entire page.

Solution

By searching I found a Java Library called AShot.

WebDriver Screenshot utility

  1. Takes a screenshot of a WebElement on different platforms (i.e. desktop browsers, iOS Simulator Mobile Safari, Android Emulator Browser)
  2. Decorates screenshots
  3. Provides flexible screenshot comparison

I was impressed with the simplicity of the sample code of capturing the entire page by AShot. So I tried AShot in Katalon Studio.

I have found AShot works like a charm.

Here I attached the screenshot taken by AShot:


How to modify report’s File Name, How to take entire page screenshot, Mouse Over is not working
[WebUI] Take Screenshot
#2

cool +1


#3

This is great. I tested it on a PC browser and it seems to work 90% of the time (the seams between the pictures were sometimes a bit off but its great.
I tried it on a phone browser and all it seems able to do is take a zoomed in screenshot. I only see the top left hand corner of the browser. Any idea what is happening?

Thanks


#4

I have no idea.
I think aShot has nothing to do with browser zooming.


#5

I think AShot takes screenshot of a single web element. I use it to screenshot only the pop-up error messages from my app, but if you set it up for taking a screenshot of the element, it will get the whole page.


#6

Stephen_Watson,

aShot supports 2 distinct method signatures:

  1. public Screenshot takeScreenshot(WebDriver driver, WebElement element) — taking a screenshot of a specific HTML element
  2. public Screenshot takeScreenshot(WebDriver driver) — taking entire page screenshot

Which method are you calling?


#7

Thanks for your reply.

It doesn’t actually zoom the browser in, the browser on the phone stays the same, it just takes a picture of the top left corner of the browser, so that’s all you see in the picture. It just makes it look like it has been zoomed.
I’ll keep search


#8

Hi, can i view the screenshot in the report generated by TestSuites? how?


#9

I can’t understand your question.


#10

Hi Kazurayam,

Do you know why my screenshot of this web page are not responsible. attached my code and screenshot
praetemptatus.agilehealthinsurance.com

WebUI.setViewPortSize(375, 667)
WebDriver driver = DriverFactory.getWebDriver()
// take screenshot of entire web page
void takeEntirePage(WebDriver webDriver, File file, Integer timeout = 300) {
Screenshot screenshot = new AShot().
coordsProvider(new WebDriverCoordsProvider()).
shootingStrategy(ShootingStrategies.viewportPasting(timeout)).
takeScreenshot(webDriver)
ImageIO.write(screenshot.getImage(), “PNG”, file)
}
String fileName = (GlobalVariable.i)+’.png’
Path pngFile = Paths.get(GlobalVariable.screenPath).resolve(fileName)
takeEntirePage(driver, pngFile.toFile(), 500)


#11

I like it too.


#12

Denis_Yu,

You showed the URL of your AUT, thank you, I can try myself.

This is my code is here.

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import java.nio.file.Files
import java.nio.file.Paths

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.openBrowser('')

WebUI.setViewPortSize(375, 667)

WebUI.navigateToUrl('https://praetemptatus.agilehealthinsurance.com/')

//WebUI.click(findTestObject('Object Repository/Page_Find Health Insurance for 2019/div_Cut your Health Insurance'))

WebUI.delay(3)

Files.createDirectories(Paths.get('tmp'))

WebUI.takeScreenshot('tmp/screenshot.png')

WebUI.closeBrowser()

I got the following screenshot.

I think, your AUT is responsible enough.

What’s wrong with your code? I do not see. You cut off some lines of your script, for example yo omitted import statements. So I can not reproduce your problem myself. Unless you showed your entire code and let me reproduce your problem on my machine, I can say nothing firmly