how to pass path Parameters in Gatling?

Hi,

how to pass path Parameters in Gatling? I have checked the documentation and couple of blogs and everyone is talking either about query parameters or parameters needed to run the query from command line.

Any idea?

The main idea is to read from the system properties inside your simulation code.

Let’s say you run your simulation with the following command:

mvn gatling:test -Dcustomproperty=somevalue

You can retrieve the value in your simulation as such:

sys.props.getOrElse(“customproperty”, “defaultvalue”)

The value will always be a String, which you can convert to any type afterwards (E.g.: using .toInt)

A more involved way could be to use property files (that looks like gatling.conf) and convert the file to scala case classes using ficus (https://github.com/iheartradio/ficus).

Hey,

not sure if I understood that correctly.

so lets say, I have a Url - https://restaurantportal//menuitems, here restaurantID is the URL Parameter.
if it was a query param I could have added

http(“Getting issues”)

.get(“https://github.com/gatling/gatling/issues”)

.queryParam(“milestone”, “1”)

there is nothing I found which is called pathParam in Gatling.

so as of now I am barcoding the path params in the URL.

Let me know if any ideas.

Oh,

I misunderstood your request.

Right, there is no path param, only query parameters that helps append ?key=value stuff at the end of a query.

You can hardcode your queries indeed. But I’d suggest using the Expression Language instead: https://gatling.io/docs/current/session/expression_el/

The idea is to save data on a request, and reuse it later on a query with the ${} syntax:

exec(
http(“Query to fetch restaurants”)
.get("…")
.check(
anyCheckThatCapturesARestaurantID… .saveAs(“restaurantID”)
)
)
// …
.exec(
http(“Using restaurantID”)
.get(“https://restaurantportal/${restaurantID}/menuitems”)
)