System environment variables are not recognized by 'engine' when running tests

I have a macOS system environment variable, ‘dev’ set. Which is essentially the baseUrl

export dev="https://int1-api.doterra.net

in my test code, the baseUrl is set by it:

private HttpProtocolBuilder httpProtocol = http
        .baseUrl(System.getenv("dev"))
        .inferHtmlResources(AllowList(), DenyList(".*\\.js", ".*\\.css", ".*\\.gif", ".*\\.jpeg", ".*\\.jpg", ".*\\.ico", ".*\\.woff", ".*\\.woff2", ".*\\.(t|o)tf", ".*\\.png", ".*detectportal\\.firefox\\.com.*"))
        .acceptHeader("*/*")
        .acceptEncodingHeader("gzip, deflate")
        .userAgentHeader("PostmanRuntime/7.29.2");

Further, I can run this from the command line, without error:
mvn gatling:test -gatling.simulationClass=customer.OccCustImpactApiLoadSimulation

Yet, when I use the recorder to run it. The failed test run indicates a reference to a completely different url. In the screenshot attachment, the url is showing up at ‘prf3.do…'. Also, included is another screenshot showing the system envirionment variable, ‘dev’ is ‘https:int1-api.doterr…’?

How can I resolve this?

I don’t get what problem you have.

Geting system variable isn’t Gatling functionality, it’s standard Java thing.
I make a test and set variable:
image

Using Simulation:

public class Case0006CommandLineParametersSimulation extends Simulation {

    int foo = Integer.getInteger("foo", 1);
    String bar = System.getProperty("bar");


    HttpProtocolBuilder httpProtocol =
            http
                    .baseUrl(System.getenv("baseUrl"));

    ScenarioBuilder scn =
            scenario("GeMi_CommandLineParametersSimulation")
                    .exec(
                            http("GeMi_CommandLineParametersSimulation_get")
                                    .get("/get?foo=" + foo + "&bar=" + bar)
                                    .check(jmesPath("args.foo").is(String.valueOf(foo)))
                                    .check(jmesPath("args.bar").is(String.valueOf(bar)))
                    );

    {
        setUp(scn.injectOpen(atOnceUsers(1)).protocols(httpProtocol));
    }
}

Run by Engine:

Result:

1 Like

Yet, when I use the recorder to run it.

The recorder is used to record, eg from your browser.
You probably mean the engine?

the url is showing up at ‘prf3.do…

baseUrl is only a prefix used for all relative urls explicitly declared in your test.

Gatling could end up performing requests to other domains because:

  • you’ve also declared absolute urls in your test
  • Gatling is following redirects, eg when during some authentication process
  • Gatling is instructed to infer HTML resources declared in your HTML responses (which is something that you do, see inferHtmlResources )

Yes, the problem is the baseUrl , which is set as an environment variable is NOT the same URL showing when running by Engine:

  • List item in my screenshots, all show the baseUrl as ‘int1-api.doterra…’ except the Engine run, which shows it as ‘prf3.doterr…’

yes, it is the Engine run which shows a different Url used than the one specified as baseUrl. This can be seen by examining the screenshots included with post

So if you have uncommented line 23 everything is working for correct address?
What gatling version you use?
For additionally check create additional system variable and try to get value from it.
Delete target folder and check if this help.
As @slandelle mentioned there can be other things where this value is overwriten.
Show us place where you make this httpRequest.

Do you ensure that IntelliJ add such environment variables when running it?

See Add environment variables and program arguments

Cheers,

Excellent suggestion, many thanks!

The http request source code of the http request is in screenshot provided. Deleting target and running was tried. It turned out to be that the IntelliJ environment variable was set to something other than the code. Thanks