Hello!
I have a long ChainBuilder where several exec statements use the same queryParam and header.
.exec(http("Statement 1")
.post("https://blabla")
.header("id", "#{id}")
.header("Content-Type", "application/xml")
.queryParam("key", "value")
.queryParam("key", "#{value}")
.queryParam("key", "#{value}")
.queryParam("key", "#{value}")
.body(StringBody(Request)))
// ...
// It repeats several times, up to ten times.
I wonder if there is any way to reuse or build the exec statements to avoid the queryParam and header repetition for each exec statement?
Hi @dariush ,
As (nearly) anything is immutable in Gatling DSL, you can easily make your own function.
public HttpBuilder withCommonParam(HttpBuilder httpBuilder) {
return httpBuilder
.header(“Content-Type”, “application/xml”)
.queryParam(“key”, “value”)
.queryParam(“key”, “#{value}”)
.queryParam(“key”, “#{value}”)
.queryParam(“key”, “#{value}”);
}
// call site
.exec(withCommonParams(http("Statement 1").post("https://blabla").header("id", "#{id}"));
Cheers!
2 Likes
Hi @sbrevet !
Thanks for the quick reply. Do you mean HttpRequestActionBuilder? I can’t find the HttpBuilder in my version of Gatling (Java) 3.9.5
Cheers,
Hi @sbrevet
I try a hybrid solution, I created a method and then use it with queryParamMap, this removes a substantial amout of code from the simulation.
.queryParamMap(method())
public static Map<String, Object> method() {
return Map.of(
"key", "#{value}",
"key", "#{value}",
);
}
system
Closed
July 26, 2023, 9:42am
5
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.