This is more a feature request than a bug...
When I try to access environment variables in karate-config.js I get an error when process.env.my_variable is seen in the code (error is 'javascript function call failed: "ReferenceError: "process" is not defined'). This is the way we access environment variables in Node.js, but I think that the karate-config.js file does not support these types of Node.js extensions to Javascript?
I like the ability to set my environment through karate.env, but I have some configurable elements (a proxy address, which is often specified in the HTTPS_PROXY environment variable) that is not fixed for a specific environment, but can still be changed. I thought I would be able to set my proxy by reading that environment variable and setting the proxy in karate-config.js, but it seems reading environment variables is not supported. I think this might be worthwhile to add to give a bit more flexibility for complex environments.
this is supported: karate.properties['my_variable']
please refer: https://github.com/intuit/karate#dynamic-port-numbers
I was referring to environment variables defined by export in Unix and set in Windows. The Java System Properties you are referring to are nice, I can probably use that, but it's not as great as the environment variables set at the OS level.
Thanks for the help and keep up the good work!
@ianrenauld AH. sorry, I read some of these issues in a hurry.
I think you have a reasonable workaround as follows, hurray for Java interop ;)
var systemPath = java.lang.System.getenv('PATH');
java.lang.System.getenv('PATH') will even work in feature files. how does that sound ? I'll add this trick to the docs. not inclined to add syntax for this, as you are the first ever to request this.
Yes! This is amazing, thank you so much!
Most helpful comment
@ianrenauld AH. sorry, I read some of these issues in a hurry.
I think you have a reasonable workaround as follows, hurray for Java interop ;)
java.lang.System.getenv('PATH')will even work in feature files. how does that sound ? I'll add this trick to the docs. not inclined to add syntax for this, as you are the first ever to request this.