Skip to main content

[WebUI] Take Screenshot

Description

Take a screenshot of the current web screen.

Keyword name: takeScreenshot

Parameters

The parameters for the WebUI keyword are as given below:

ParameterParameter TypeRequiredDescription
fileNameStringOptionalRepresents the path to the saved image. The path can be an absolute or relative path.
flowControlFailureHandlingOptionalSpecify failure handling schema to determine whether the execution should be allowed to continue or stop.
screenshotOptionsMapOptionalRepresents the information to be printed on the captured screenshot.

The screenshotOptions parameter has the following properties:

ParameterParameter TypeRequiredDescription
TextStringMust not be null or emptyDetermines the information to be printed on the captured screenshot. This string should be limited to 100 characters.
xIntegerOptionalx pixels from the left side of the image. The default is 0.
yIntegerOptionaly pixels from the top of the image. The default is 0.
fontStringOptionalFont name. The default is Arial.
fontSizeIntegerOptionalSize of font. The default is 12, maximum is 50.
fontColorStringOptionalHex string of color. Default is "#000000" (black).
fontStyleFontStyleOptionalCan be Plain, Italic or Bold. Default is Plain.

For further information on standard map literal syntax, refer to: The Groovy Development Kit - Collections-Maps.

Note:

Example

Take a screenshot of your current browser after logging in. By default, the screenshots are saved to your Katalon Studio folder:
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.checkpoint.CheckpointFactory as CheckpointFactory
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as MobileBuiltInKeywords
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testcase.TestCaseFactory as TestCaseFactory
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testdata.TestDataFactory as TestDataFactory
import com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywords
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywords
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable

'Open browser and navigate to AUT'
WebUI.openBrowser(GlobalVariable.G_SiteURL)

'Input username'
WebUI.setText(findTestObject('Page_Login/txt_UserName'), Username)

'Input password'
WebUI.setText(findTestObject('Page_Login/txt_Password'), Password)

'Click on new_btn'
WebUI.click(findTestObject('Page_Login/btn_Login'))

'Take a screenshot after logging in'
WebUI.takeScreenshot()

'Close browser'
WebUI.closeBrowser()
Store your screenshot in a custom location after logging in:
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.checkpoint.CheckpointFactory as CheckpointFactory
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as MobileBuiltInKeywords
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testcase.TestCaseFactory as TestCaseFactory
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testdata.TestDataFactory as TestDataFactory
import com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywords
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywords
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable

'Open browser and navigate to AUT'
WebUI.openBrowser(GlobalVariable.G_SiteURL)

'Input username'
WebUI.setText(findTestObject('Page_Login/txt_UserName'), Username)

'Input password'
WebUI.setText(findTestObject('Page_Login/txt_Password'), Password)

'Click on new_btn'
WebUI.click(findTestObject('Page_Login/btn_Login'))

'Take screenshot after logging in'
WebUI.takeScreenshot('E:\\screenshot.png')

'Close browser'
WebUI.closeBrowser()
Sort and store screenshots by projects using relative paths:
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.checkpoint.CheckpointFactory as CheckpointFactory
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as MobileBuiltInKeywords
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testcase.TestCaseFactory as TestCaseFactory
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testdata.TestDataFactory as TestDataFactory
import com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywords
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywords
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable

'Open browser and navigate to AUT'
WebUI.openBrowser(GlobalVariable.G_SiteURL)

'Input username'
WebUI.setText(findTestObject('Page_Login/txt_UserName'), Username)

'Input password'
WebUI.setText(findTestObject('Page_Login/txt_Password'), Password)

'Click on new_btn'
WebUI.click(findTestObject('Page_Login/btn_Login'))

'Take screenshot after logging in'
WebUI.takeScreenshot('Test/Demo.png')

'Close browser'
WebUI.closeBrowser()
Print text on your screenshots:
  • Add the current timestamp to your screenshot:
def timestamp = new Date().format("YYYY-MM-dd HH:mm:ss")
WebUI.takeScreenshot(["text" : timestamp])
  • Add text Katalon Studio at position (10, 20):
WebUI.takeScreenshot(["text" : "Katalon Studio", "x" : 10, "y" : 20])
  • Add text Katalon Studio at position (10, 20) with font Courier, size 24, and gray color:
WebUI.takeScreenshot(["text" : "Katalon Studio", "x" : 10, "y" : 20, "font" : "Courier", "fontSize" : "24", "fontColor": "#808080"])
  • Take a screenshot, save it at D://Document. Add text Katalon Studio at position (10, 20) with font Courier, size 24 in gray:
WebUI.takeScreenshot(["text" : url, "x" : 10, "y" : 20, "fontColor" : "#FF3399", "fontStyle" : "Bold", "fontSize" : 30])
Was this page helpful?