de-duplicate specification of queryParams

I have several calls like this:

.post(…)
.queryParam(“authToken”, “${authToken}”)
.queryParam(“country”, “${country}”)

.check(status.is(StatusCodes.NoContent.value)))

.delete(…)
.queryParam(“authToken”, “${authToken}”)
.queryParam(“country”, “${country}”)

.check(status.is(StatusCodes.NoContent.value)))

.get(…)
.queryParam(“authToken”, “${authToken}”)

.queryParam(“country”, “${country}”)

Is there any way to consolidate the queryParams so I don’t have to duplicate them for all calls? (I actually have more than just 3…)

Stig

Not in the DSL, but why don’t you simply write a def?
Here’s an example: https://github.com/excilys/gatling/wiki/Handling-JSF

I have nothing against writing a def :slight_smile:

I am using 2.0.0-SNAPSHOT. I didn’t find EvaluatableString but the migration instructions seemed to imply I should use Expression[String] instead, so I tried this:

def execPost(name: String, url: Expression[String]) = exec(
http(name)
.post(url)
.queryParam(“country”, “${country}”)
.queryParam(“authToken”, “${authToken}”)
.check(status.is(StatusCodes.NoContent.value)))

However, when I call it like so:

execPost(“Add myself to Foos”, "/api/foos/${uid})

I get:

java.net.URISyntaxException: Illegal character in path at index $N: https://secret.herokuapp.com/api/foos/${uid}

Where $N is the index of where ${uid} starts in the url. Is Expression[String] the wrong type to use? What should I use instead?

Stig

Ouch, that’s a very very tricky one.
Fixed, thanks for reporting!

https://github.com/excilys/gatling/issues/1148

My fix actually didn’t work…
Please import io.gatling.core.session.Expression explicitly and it should run fine.

Thanks! It works well.

Stig