Problem getting environment variables MacOS

Hi!

I’m facing some trouble with environment variables.
In my project, I have some external jar dependencies. One of them is a library that I, myself, have developed and also have been using for the past 6 months with no problem at all, but recently I moved from Windows to MacOS and I am not capable of getting the environment variables that are called inside this library (System.getenv()).

These environment variables are set in the bash profile and, from inside the library or any other location, I can use and see them correctly. The problem is when I use the library from inside Katalon. Library methods are called but variables seem to be not recovered.

Does anyone know why is this happening?
Any response would be appreciated.

Thanks!!

How do you start Katalon Studio on Mac? Possibly you would click the KS icon in the Dock to launch it. In this way your ~/.bash_profile will not be referred to, and the environment variables will not be present.

A workaround: open Mac Terminal app to activate a bash interpreter (~/.bash_profile will be sourced and environment variables will be created), then launch KS by executing a command :

$ /Applications/Katalon\ Studio.app/Contents/MacOS/katalon

2 Likes

The environment variables are, in some situations, difficult to configure.

You can change the library, can’t you? Then you can make the library configurable by some alternative way other than the environment variables.

Thanks, man!
That worked! I’ll try to change things inside the library but for now, it is not possible bc the library is used for more applications that need an environment variable.

Hi,
I think the problem seems to reapper on 9.6.0 version.
the environment variables doesn’t seem to work on latest version of Katalon studio.
any work arounds?

Hi there,

Thank you very much for your topic. Please note that it may take a little while before a member of our community or from Katalon team responds to you.

Thanks!

Let me show you an example. I used Katalon Studio v9.0.0 Free version.

I launched Katalon Studio v9.0.0 by double-cliking the desktop icon. I wrote a test case:

println Sysmte.getenv('PATH')

I ran it. I got an output in the console:

2024-08-22 14:00:29.689 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2024-08-22 14:00:29.693 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/TC3
2024-08-22 14:00:30.470 DEBUG testcase.TC3                             - 1: println(System.getenv("PATH"))
/usr/bin:/bin:/usr/sbin:/sbin
2024-08-22 14:00:30.533 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/TC3

The value of “PATH” environment variable was very short.

/usr/bin:/bin:/usr/sbin:/sbin


On the other had, in the Terminal window with Bash interpreter I executed a shell command

$ echo $PATH

It showed a very long string value as the following screenshot shows

Another case, in the Terminal window, in the bash shell interaction, I launched Katalon Studio from command line. I ran the same test case as above.

This time I could see a very long string values as “PATH”


This experiments tells us that

System.getenv("PATH")

returned different values in the following 2 cases:

  1. when Katalon Studio was launched by double-clicking the desktop icon
  2. when Katalon Studio was launched by commandline interpreter (bash)

How come these 2 cases differs?

The key factors are Bash, .bash-profile and .bashrc

In the 2nd case, the bash interpreter forks a new OS process in which Katalon Studio runs. Usually bash executes the .bash-profile shell script and the .bashrc shell script on its startup. These shell scripts build up the PATH environment variables with a lot of custom path information. Therefore in the 2nd case, a call to System.getenv("PATH") you will get a rich value.

In the 1st case, on the other hand, a new process will be forked by macOS without bash. macOS won’t execute .bash-profile and .bashrc. Therefore, you will find the PATH environment variable is — how should I express it? — plain.


This behavior doesn’t depend on the version of Katalon Studio. v9.6.0 will work the same as v9.0.0.

1 Like