httpProtocols with 2 different base urls

Hi Team,

I have a scenario where in 1 scenario itself I have to call APIs having 2 different urls. I have to handle it using httpProtocols only and not providing full url since the baseURL is dynamic for the scenario which changes based on the environment variable.

Example -

baseURL1 - perf (if envt variable is perf) , newperf (if envt variable is newperf)

baseURL2 - abc (if envt variable if perf), xyz (if envt variable is newperf)

Both the urls (baseURL1 and baseURL2) takes different headers as well. Also there is need for it to be in same scenario only. Keeping static URL will defeat the purpose of dynamic url based on the envt variable.

I see the .protocols method can take more than 1 httpProtocols but not sure how they are passed in the scenario. If possible, share the sample code as well.

Please check my Case0006CommandLineParametersSimulation from my GeMi Gatling Examples in JAVA

Not sure I get your question right.

The baseUrl mecanism prepends a String to all relative urls in the scenarios the httpProtocol is defined on (either at the scenario level or globally at the setUp level).
There’s also baseUrls (plural) that accepts multiple entries but they mut be equivalent, used to do round robin between multiple domains or addresses.

My understanding is that this doesn’t work for you because you want to use 2 different domains in the same scenario.
Then, you can only use the baseUrl mechanism for the first one. For the second one, you have to manually concatenate and pass absolute urls.

Assuming Java:

String env = System.getEnv("envt")
String baseURL1 = "perf".equals(env) ? "perf" : "newperf";
String baseURL2 = "perf".equals(env) ? "abc" : "xyz";

// use baseUrl for the first one
HttpProtocolBuilder httpProtocol =

// concatenate to have absolute url for all other requests that must use the second one
http("request").get(baseURL2 + "/foo")

thanks but this is not what I was looking for. But I understand from the replies that it isn’t possible in gatling.
The reason for using two different httpProtocols was not just two different baseurls but the headers as well.
Anyway, for now I have proceeded with 1 baseurl and 1 absolute url.

HttpProtocol lets you define a default configuration (baseUrl for relative urls, default headers). You can have one per scenario, but not multiple ones, it’s neither possible nor makes sense.

Not possible is fine but I am not sure why would say it doesn’t make sense :slight_smile: I could have scenario where I am expected to hit more than 1 baseURLs and have the default headers etc for them.
I’ve had similar requirements previously as well and used in LoadRunner, but understand the limitation of Gatling. Nevertheless, thank you !

baseUrl = prepend ALL relative urls with this prefix.

How could this possibly be multivalued? You would need a criterion of some some to know which to apply.

Then, I suspect you haven’t realized that as Gatling is code, you can write factory methods, eg:

def type1GetRequest(name: String, url: String) =
  http(name).get(baseUrl1 + url).headers(type1Headers)

def type2GetRequest(name: String, url: String) =
  http(name).get(baseUrl2 + url).headers(type2Headers)
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.