Could not able to access environmental variables

I could not able to access environmental variables from Katalon Studio for remote web driver capabilities since it is a String. Actually I am using jenkins and saucelabs integrated with katalon studio. Jenkins generates some environmental variables in runtime and I could not able to access those variables. Please help me with this regard.

are you using Docker with Katalon for test execution?

I have a related problem I put there as I’m unable to open myself a new topic (maybe as a newbie, I have first to gain some privileged access?)

I would like to execute a Katalon studio script from a Java program calling it (and for this I need to set up properly the execution environment).

To achieve this I set up in Intellij a new Groovy project.

I copied all the jars from the plugins directory of the Katalon Studio Eclipse based IDE to have them available in my Groovy project.

Then I copied the intended Groovy script from Katalon Studio to Intellij, as a new Groovy file.

I saw that I had to select JDK8 instead of JDK11 to avoid some Groovy startup errors.

Next step was to avoid a null pointer exception from failure to load a ChromeDriver instance.

I wrote the following code
setProperty(“webdriver.chrome.driver”, “C:\lib\chromedriver.exe”)
options = new ChromeOptions();
options.setHeadless(false);
options.addArguments(“enablePageLoadTimeout”, “20”)
driver = new ChromeDriver(options);
//Link instanciated ChromeDriver to WebUI
DriverFactory.changeWebDriver(driver)
//Use the new defined browser but it fails due to reinitialization of properties with missing config when the corresponding values should have been taken from the already instanciated ChromeDriver!
WebUI.openBrowser(’’)

See the corresponding stack trace,

java.lang.NullPointerException
at com.kms.katalon.core.configuration.RunConfiguration.getExecutionGeneralProperties(RunConfiguration.java:434)
at com.kms.katalon.core.webui.driver.DriverFactory.isEnablePageLoadTimeout(DriverFactory.java:1176)
at com.kms.katalon.core.webui.driver.DriverFactory.setTimeout(DriverFactory.java:769)
at com.kms.katalon.core.webui.driver.DriverFactory.changeWebDriverWithoutLog(DriverFactory.java:248)
at com.kms.katalon.core.webui.driver.DriverFactory.changeWebDriver(DriverFactory.java:240)
at com.kms.katalon.core.webui.driver.DriverFactory$changeWebDriver.call(Unknown Source)
at KatalonTest.run(KatalonTest.groovy:42)

So my question is how I can avoid such a call to already filled configuration options (i.e. the isEnabledPageLoadTimeout setting)?
Or, if it is not possible to avoid such a parasitic re-initialization call, then how can I recreate a proper configuration in my Intellij project i.e. what exactly has to be copied/reproduced from the Katalon Studio Eclipse environment for that (like e.g. default property file(s) ?

Some hints

One can have a glimpse of what The RunConfiguration code is doing from https://github.com/katalon-studio/katalon-studio-testing-framework/blob/master/Include/scripts/groovy/com/kms/katalon/core/webui/driver/DriverFactory.java but this code is for Katalon 5.10 and has not been updated since (AFAIK).

Also, environment setting is complicated by the fact that a Katalon Studio project is automatically generating a GlobalVariable instance per project which itself is taken as source to fill a RunConfiguration instance.

AFAIK I’ll don’t need all that paraphernalia, but instead just avoid to redefine what is already set up from my ChromeOptions but unfortunately overriden from a call to a failing RunConfiguration when the browser is opened.

Why would you do that?

I have a bunch of testcases I would run from a Java orchestrating program that is automating data aggregation, so I figured my approach as a possible solution. It would also be possible to remotely call the Katalon Studio engine but my approach was more fine grained IMHO.

the problem is that you would need to, in my opinion, include all libraries that supports Katalon into your environment. and also then lot of stuff is generated.
in your place i would go for calling Katalon CLI version with well prepared test suites that will fulfill your need.
I would also consider option to write orchestration in Katalon as Java/Groovy script and run it from there.
Katalon studio is not only IDE that runs tests (like Eclipse+Groovy or InteliJ+Groovy) it’s more deeply integrated with test scripts. (at least that’s my understanding of Katalon studio)

can you describe how are you trying to access environmental variables?
i have following script that sets globlal variables based on values it reads from System environment.

import com.kms.katalon.core.annotation.BeforeTestCase
import com.kms.katalon.core.annotation.BeforeTestSuite
import com.kms.katalon.core.context.TestCaseContext
import com.kms.katalon.core.context.TestSuiteContext
import com.kms.katalon.core.util.KeywordUtil

import internal.GlobalVariable as GlobalVariable

class PrepareEnvVariables {
	/**
	 * Executes before every test suite starts.
	 * @param testSuiteContext: related information of the executed test suite.
	 */
	@BeforeTestSuite
	def prepareEnvVariables(TestSuiteContext testSuiteContext) {
		KeywordUtil.logInfo(testSuiteContext.getTestSuiteId())
		def gVars = ['seleniumBoxToken_password','runOnBrowser','iriPath','IRI_ACC_DB','IRI_ACC_DB_USER','IRI_ACC_DB_PASSWORD']
		gVars.each{
			if(System.getenv("${it}") != null){
				GlobalVariable."${it}" = System.getenv("${it}")
			}
		}
	}
}

then in bamboo (Jenkins will be similar)

docker run \
    --volume ${bamboo.working.directory}/katalon/project:/tmp/katalon_execute/project \
    -t \
    --rm \
    -v "$(pwd)":${bamboo.working.directory} \
    -w ${bamboo.working.directory} \
    -e "IrampCCDBPassword=$bamboo_IrampCCDBPassword" \
    -e "IrampCCDBUser=$bamboo_IrampCCDBUser" \
    -e "runAsPassword=$bamboo_runAsPassword" \
    -e "runAsUser=$bamboo_runAsUser" \
    -e "runOnBrowser=$bamboo_runOnBrowser" \
    -e "seleniumBoxToken_password=$bamboo_seleniumBoxToken_password" \
    katalonstudio/katalon:6.3.1 /bin/bash -c "cp /tmp/katalon_execute/project/MyVault/cacerts /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/security/ && katalon-execute.sh \
    -browserType=\"Chrome\" \
    -retry=0 -statusDelay=15 \
    -testSuitePath=\"Test Suites/Business/Calculation\" \
    -executionProfile=\"bamboo-cc-dev\"

hope this helps