Katalon.properties file and JVM System Property katalon.user.home

Using OS-level environment variable would be an option for you.

In the command line or windows bat script you would do:

>set baseURL=http://www.example1.com>...>.\katalon -runMode=console ...

and in TestListener or Test Case you do

if (System.getenv("baseURL") != null) {    GlobalVariable.baseURL = System.getenv("baseURL")}
3 Likes

That looks like a good option. I will try it out and check if that would solve my problem smart and easy.

Thanks for your help! Much appreciated :slight_smile:

kazurayam said:

Using OS-level environment variable would be an option for you.

In the command line or windows bat script you would do:

>set baseURL=http://www.example1.com>...>.\katalon -runMode=console ...

and in TestListener or Test Case you do

if (System.getenv("baseURL") != null) {    GlobalVariable.baseURL = System.getenv("baseURL")}

I have tried to make something like that for hit the result to test railt but it doesn’t work

this my code on Testlistener/hook’s

if (System.getenv("runMode") == "console") {			
GlobalVariable.UpdateTestRail = System.getenv("updateTestRail")
GlobalVariable.TestRailRunId = System.getenv("testRailRunID")	
}
./Katalon\ Studio.app/Contents/MacOS/katalon --args -noSplash  -runMode=console -updateTestRail=true -testRailRunID=5193 -consoleLog -projectPath="/Users/automation-web/Automation-Web.prj" -retry=0 -testSuiteCollectionPath="Test Suites/TestSuiteCollection/Run Smoke Test 1(Chrome)"

I have tried also as you explain, by typing and set parameters but not working

>set updateTestRail=true>set testRailRunID=5193>./Katalon\ Studio.app/Contents/MacOS/katalon --args -noSplash  -runMode=console -consoleLog -projectPath="/Users/automation-web/Automation-Web.prj" -retry=0 -testSuiteCollectionPath="Test Suites/TestSuiteCollection/Run Smoke Test 1(Chrome)"

but it doesn’t work

Any messages in the log?

Did you defined _UpdateTestRail and _TestRailRunId in the defaul Profile before running the script?

You need to defind variables in the defaul Profile.PNG

1 Like

yes I have:

It’s looks like I missed something, did I need to use jar file which is you provided and create katalon properties?

if I uses katalon properties it means I still need to open file and edit the properties before execute the command right? is there any way to make it put the variable like usually uses for executing katalon via command line, by typing -updateTestRail=true -testRailRunId=5191

Screen Shot 2018-10-09 at 13.06.09.png

Yes, you need to import MultiSourcedProperties-1.0.jar file into Katalon Studio in order to load the contents of katalon.properties file.

You can download the jar from

  1. https://github.com/kazurayam/MultiSourcedProperties/releases
1 Like

is there any way to make it put the variable like usually uses for executing katalon via command line, by typing -updateTestRail=true -testRailRunId=5191

No, there isn’t. It is the very reason why you are now working on using OS-level environment variable, isn’t it? Using environment variables, you are going to overwrite the values of GlobalVariables.

1 Like

I have installed your jar.

And for properties I just need to uses properties which is generated from Build CMD > Generate Property File and replaces it with my variable, right?

this is my content of console.properties

this my code on Testlistener/hook’s

if (System.getenv("runMode") == "console") {			
GlobalVariable.UpdateTestRail = System.getenv("updateTestRail")
GlobalVariable.TestRailRunId = System.getenv("testRailRunID")	
}

I tried to uses my properties but it’s gives result like this:


Then I did,

$cd /Applications/$set updateTestRail=true$set testRailRunID=5193$./Katalon\ Studio.app/Contents/MacOS/katalon --args -noSplash  -runMode=console -consoleLog -projectPath="/Users/automation-web/Automation-Web.prj" -retry=0 -testSuiteCollectionPath="Test Suites/TestSuiteCollection/Run Smoke Test 1(Chrome)"

but still my test rail not updated

Screen Shot 2018-10-09 at 14.21.49.png

Screen Shot 2018-10-09 at 15.02.21.png

console.properties? — it is generated by Katalon studio, and nothing to do with what I call “katalon.properties”.

1 Like

Alex,

I am afraid you haven’t check “How to” sections in the README of https://github.com/kazurayam/KatalonPropertiesDemo
Please read it first and try again.

1 Like

kazurayam said:

Alex,

I am afraid you haven’t check “How to” sections in the README of https://github.com/kazurayam/KatalonPropertiesDemo
Please read it first and try again.

sorry for my bad english.
I tried using your KatalonPropertiesDemo repository, it’s run well if I run with open katalon GUI, but it’s failed when I tried to execute via command line.
I execute like this:

$cd /Applications/$set GlobalVariable.hostname=test
$./Katalon\ Studio.app/Contents/MacOS/katalon --args -noSplash  -runMode=console -consoleLog -projectPath="/Users/automation-web/Automation-Web.prj" -retry=0 -testSuiteCollectionPath="Test Suites/TestSuiteCollection/Run Smoke Test 1(Chrome)"

This are for logs:



10-09-2018 04:28:03 PM - [RUN_DATA] - Logging run data 'hostName' with value 'btpn - 10.10.24.118'10-09-2018 04:28:03 PM - [INFO]   - >>> GlobalVariable.hostname default value: ''10-09-2018 04:28:03 PM - [END]    - End action : comment10-09-2018 04:28:03 PM - [START]  - Start action : Statement - preferedHostname = props.getProperty("GlobalVariable.hostname")10-09-2018 04:28:03 PM - [END]    - End action : Statement - preferedHostname = props.getProperty("GlobalVariable.hostname")10-09-2018 04:28:03 PM - [START]  - Start action : Statement - If (preferedHostname != null)10-09-2018 04:28:03 PM - [END]    - End action : Statement - If (preferedHostname != null)10-09-2018 04:28:03 PM - [START]  - Start action : Statement - Else10-09-2018 04:28:03 PM - [START]  - Start action : comment10-09-2018 04:28:03 PM - [INFO]   - >>> GlobalVariable.hostname stays unchanged

it’s looks like the value not inserted into GlobalVariable.hostname

Alex,

You happened to point out a weak point of the MultiSourcedProperties-1.0.jar. Thank you.

-------

As https://github.com/kazurayam/KatalonPropertiesDemo explains: you create katalon.properties file in java.util.Properties format. The file can be located in various locations as the following list shows. If a single Property is declared in multiple katalon.properties files at different locations, the last wins:

  1. <current directory>/katalon.properties is loaded if exists
  2. $HOME/katalon.properties on Mac/Linux, %USERPROFILE%\katalon.properties on Windows is loaded if exists
  3. If environment variable KATALON_USER_HOME is given, then a katalon.properties file under the directory new File(System.getenv('KATALON_USER_HOME')) is searched and loaded
  4. If JVM System Property katalon.user.home is given, then a katalon.properties file under the directory new File(System.getProperty("katalon.user.home")) is searched and loaded.

When you run a project with Katalon Studio GUI, the will be same as -projectPath="<katalon project dir>". In this situation, your <katalon project dir>/katalon.properties file will be found by com.kazurayam.MultiSourcedProperties object running in the GUI.

But when you run in console mode, you are required to move the current directory to the Katalon installation directory, so you will do $ cd /Applications/Katalon\ Studio.app/Contents/MacOS. This causes the current directory to be moved. In this situation com.kazurayam.MultiSourceProperties object running in the console mode fails to find the <katalon project dir>/katalon.properties file as <current directory>/katalon.properties.

-----------

You have a workaround. Please do as follows:

$ set KATALON_USER_HOME=<katalon project dir>$ cd /Applications/Katalon\ Studio.app/Contents/MacOS$ ./katalon -runMode=console ....
1 Like

Maybe I’m a little late in this discussion - or I missed or misunderstand something, then please excuse me. :slight_smile: But is there actually a certain reason why you don’t want to use the profile function built into Katalon Studio the way it is supposed to for the quite simple purpose of @Said A… and @Alex Jack to exchange a url when calling it via command line? You can simply create different profiles, each with a different url string variable, and then use the command line option -executionProfile to select the profile you want to use. Isn’t that what you’re trying to do?

Drunda Nibel said:

Maybe I’m a little late in this discussion - or I missed or misunderstand something, then please excuse me. :slight_smile: But is there actually a certain reason why you don’t want to use the profile function built into Katalon Studio the way it is supposed to for the quite simple purpose of @Said A… and @Alex Jack to exchange a url when calling it via command line? You can simply create different profiles, each with a different url string variable, and then use the command line option -executionProfile to select the profile you want to use. Isn’t that what you’re trying to do?

I have explained the reason in my comment above at 9/28/2018 to this issue.

Please find the date of my initial post — 3/27/2018. At that time we had v 5.3.x which did not have Execution Profile yet. Still I wanted a method to specify parameters (username, password) runtime. Therefore I invented the method driven by katalon.properties. Later in April 2018, Execution Profile was introduced to Katalon Studio at v5.4.0.

1 Like

Yes, I had read that. But the discussion about difficulties in dealing with dependencies in order to get your undoubtedly great properties approach to work continued until October. And the second reason to be able to protect sensitive data from being published with the Git repository also applies to Katalon’s profile data, which can also be included in the .gitignore file, can’t it?

Despite all the merits your solution has earned, I just thought Said A. and Alex Jack might have missed the essence and power of this profile feature now available in Katalon Studio.

There is another simple way to keep sensitive data out of the project directory. Just use

evaluate(new File(myLocalFilePath))

whenever a Groovy script file should be included whose code content should not be visible at this point.

Would you please explain this approach a little more. As setting OS-level env variable is not an apt way to solve this but a great workaround.
Thanks you in adv.

habin,

Sorry, I do not see what you want to be explained more.

Do you want to say that you prefer OS-level environment variable to katalon.properites file?

What is your problem to solve?

Are you aware that Katalon Studio version 5.10 supported a new feature: Override Profile Variables via Command line Execution Mode ?
https://docs.katalon.com/katalon-studio/new/version-510.html#support-skip-test-case-method-in-test-listener

1 Like

Let me introduce my rencent idea of passing runtime parameters, alternative to katalon.properties

1 Like

I was not aware about this release feature. Thanks a lot.