Take a manually screenshot

Hello everyone! I hope you can help me.
I need to take different screenshots during a test case execution, and it should be taken manually because I need to have the evidence on different steps. The screenshot should also capture the URL webpage as part of the evidence. I have used the “TakeScreenshot” function, but it doesn’t work because it takes just a part of the page. I need something like these:

I no need to scroll down, just to take a full screenshot of the webpage including the URL, as you can see in the example.

Any suggestion? Thank you.

1 Like

It seems that you do not differentiate the following 2 things:

  1. A screenshot of the browser window, which is usually taken by a manual operation such as Command+Shift+F4 on Mac.

  2. A screenshot of a web page taken via Selenium WebDriver, as explained in some articles.

These 2 things are made by 2 completely different ways of processing. The case 1 includes the screenshot of “address bar”. The case 2 does NOT include the “address bar”.

WebUI.takeScreenshot() keyword is an instance of the case 2, which does not include “address bar”.

No, you can not include the URL automatically. The URL is displayed in the “address bar” of a browser window. The address bar is not a part of the rendered web page. Therefore the screenshot of a web page will not contain the “address bar”.

1 Like

WebUI.takeScreenshot keyword supports a feature “print text on your screenshots”:

With this feature you should be able to print the URL as a text string into the screenshot taken by WebUI.takeScreenshot keyword.

Samle code:

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

String url = 'http://demoaut.katalon.com'
File file = new File("screenshot.png")

WebUI.openBrowser('')
WebUI.setViewPortSize(1000, 800)
WebUI.navigateToUrl(url)
WebUI.takeScreenshot(file.toString(), 
	["text" : url, 
		"x" : 10, "y" : 20, 
		"fontSize" : 48, "fontColor": "#808080"])
WebUI.closeBrowser()

Sample output:

Please find on the top left corner of the screenshot image, you can find a string http://demoaut.katalon.com is printed.

1 Like

You wrote you want a full page screenshot. Then you want to use WebUI.takeFullPageScreenshot keyword

I checked the doc and found this keyword does not support the feature of “printing text in screenshot”. I don’t know why.

I personally do not like the idea of printing the URL on the screenshot image. The URL printed into the image is visible for human only, is not re-usable for software at all. I personally will never utilize this.

1 Like

@Igaravaglia

You want to keep the page’s meta data (such as the URL of the web page) with a screenshot images. You asked how to achieve it.

I understand you. I think that it is a quite reasonable requirement. A screenshot image without the information which URL the image was taken from — it is a useless garbage, I think.

But, I would tell you, it is a difficult requirement to meet. It would require a bunch of well-designed classes to build a database of downloaded web resources (such as screenshots) with associated meta data (such as URL). Katalon Studio is not capable of it.

1 Like

I use something like this:

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import java.time.format.DateTimeFormatter
import java.time.LocalDateTime
import java.util.Date

String url = 'http://demoaut.katalon.com'
//Date format: yyyy-MM-dd HH:mm:ss.SSS
LocalDateTime fileName = LocalDateTime.now()
DateTimeFormatter fileName_formatter = DateTimeFormatter.ofPattern("HHmmss")
def rmfileName = "ScreenShot" + fileName.format(fileName_formatter) + ".png"
println("rmfileName: " + rmfileName)

File file = new File(rmfileName)
def Directory = (System.getProperty('user.home') + '\\Downloads\\') + file
WebUI.openBrowser('')
WebUI.navigateToUrl(url)
WebUI.takeScreenshot(Directory.toString(), ["text" : url, "x" : 10, "y" : 20, "fontColor" : "#ff0000", "fontStyle" : "Bold", "fontSize" : 24])
WebUI.closeBrowser()
//fontColors: https://www.colorhexa.com