I’m trying to update the report[screenCaptureOption] setting via script so that I can sometimes allow screenshots and sometimes not (i.e., I don’t want pages with sensitive to take screenshots, but others are fine).
I’m trying to update with RunConfiguration.setExecutionSetting, but I’m getting a null pointer exception. I’ve checked the RunConfiguration documentation but it didn’t clear anything up.
Any help folks can give is appreciated!
My execution properties look like this (the one I want to change is in bold):
[autoApplyNeighborXpaths:false, ignorePageLoadTimeoutException:false, timeCapsuleEnabled:false, executionProfile:default, excludeKeywords:[verifyElementPresent, verifyElementNotPresent], xpathsPriority:[[left:xpath:attributes, right:true], [left:xpath:idRelative, right:true], [left:dom:name, right:true], [left:xpath:link, right:true], [left:xpath:neighbor, right:true], [left:xpath:href, right:true], [left:xpath:img, right:true], [left:xpath:position, right:true], [left:xpath:customAttributes, right:true]], timeout:30.0, actionDelay:0.0, methodsPriorityOrder:[[left:XPATH, right:true], [left:CSS, right:true], [left:BASIC, right:true], [left:IMAGE, right:true]], proxy:{“proxyOption”:“USE_SYSTEM”,“proxyServerType”:“HTTP”,“username”:“”,“password”:“”,“proxyServerAddress”:“127.0.0.1”,“proxyServerPort”:0,“exceptionList”:“”,“applyToDesiredCapabilities”:true}, defaultFailureHandling:STOP_ON_FAILURE, terminateDriverAfterTestCase:false, defaultPageLoadTimeout:30.0, report:[videoRecorderOption:[enable:false, useBrowserRecorder:true, videoFormat:AVI, videoQuality:LOW, recordAllTestCases:false, allowedRecordIfFailed:true, allowedRecordIfPassed:false], screenCaptureOption:true, reportFolder:/var/folders/rk/6ltbhf7j4gl59_84khbd1hrh0000gn/T/Katalon/Test Cases/UnitTests/KeywordUTs/UTKW001_GetTestCaseID/20240802_141716], enablePageLoadTimeout:false, terminateDriverAfterTestSuite:true, useActionDelayInSecond:SECONDS, testDataInfo:[:], selfHealingEnabled:false]
My script (currently in a listener) is:
import com.kms.katalon.core.annotation.BeforeTestCase
import com.kms.katalon.core.annotation.BeforeTestSuite
import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.context.TestCaseContext
import com.kms.katalon.core.context.TestSuiteContext
import com.kms.katalon.core.util.KeywordUtil
import internal.GlobalVariable
class TurnOffScreenCapture {
/**
* Executes before every test case starts.
* @param testCaseContext related information of the executed test case.
*/
@BeforeTestCase
def sampleBeforeTestCase(TestCaseContext testCaseContext) {
if (!GlobalVariable.screenShotsDisabled) {
// Don't run if this has already been run by the test suite
turnOffScreenShots()
}
}
/**
* Executes before every test suite starts.
* @param testSuiteContext: related information of the executed test suite.
*/
@BeforeTestSuite
def sampleBeforeTestSuite(TestSuiteContext testSuiteContext) {
turnOffScreenShots()
}
private void turnOffScreenShots() {
try {
// Get the current execution properties
Map<String, Object> executionProperties = RunConfiguration.getExecutionGeneralProperties()
if (executionProperties == null) {
KeywordUtil.markWarning("Execution properties are null")
} else {
KeywordUtil.logInfo("Execution properties: " + executionProperties.toString())
// Check if 'report' key exists and is a Map
if (executionProperties.containsKey('report') && executionProperties['report'] instanceof Map) {
executionProperties['report']['screenCaptureOption'] = false // or true to enable
KeywordUtil.logInfo(executionProperties['report']['screenCaptureOption'].toString())
} else {
KeywordUtil.markWarning("Report settings not found or not a Map in execution properties")
}
// Log the final state of executionProperties before setting it
KeywordUtil.logInfo("Final execution properties before setting: " + executionProperties.toString())
// Apply the updated execution settings
RunConfiguration.setExecutionSetting(executionProperties) // throws NullPointerException
// Set this variable to true to indicate other test cases in the suite don't need to run it
GlobalVariable.screenShotsDisabled = true
}
} catch (Exception e) {
KeywordUtil.markError("Error while updating execution settings: " + e.message)
e.printStackTrace()
}
}
}