[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:
Parameter | Parameter Type | Required | Description |
---|---|---|---|
fileName | String | Optional | Represents the path to the saved image. The path can be an absolute or relative path. |
flowControl | FailureHandling | Optional | Specify failure handling schema to determine whether the execution should be allowed to continue or stop. |
screenshotOptions | Map | Optional | Represents the information to be printed on the captured screenshot. |
The screenshotOptions
parameter has the following properties:
Parameter | Parameter Type | Required | Description |
---|---|---|---|
Text | String | Must not be null or empty | Determines the information to be printed on the captured screenshot. This string should be limited to 100 characters. |
x | Integer | Optional | x pixels from the left side of the image. The default is 0. |
y | Integer | Optional | y pixels from the top of the image. The default is 0. |
font | String | Optional | Font name. The default is Arial. |
fontSize | Integer | Optional | Size of font. The default is 12, maximum is 50. |
fontColor | String | Optional | Hex string of color. Default is "#000000" (black). |
fontStyle | FontStyle | Optional | Can 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:
- Supported fonts are Operating System (OS) fonts. You can find a list of font names for your operating system in the links given below:
Example
Take a screenshot of your current browser after logging in. By default, the screenshots are saved to your Katalon Studio folder:Store your screenshot in a custom location after logging in:Sort and store screenshots by projects using relative paths:Print text on your screenshots:
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()
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()
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()
- 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])