har123
har123

Reputation: 59

Pass runtime arguments in Gatling

I am trying to pass runtime args while running gatling tests for couple of fields. For example I am trying to pass number of users dynamically when running the test. How can I do that?

Upvotes: 0

Views: 1258

Answers (2)

Stéphane LANDELLE
Stéphane LANDELLE

Reputation: 6623

This is documented in the official documentation:

This can be done very easily with additional JAVA_OPTS in the launch script:

JAVA_OPTS="-Dusers=500 -Dramp=3600"

val nbUsers = Integer.getInteger("users", 1)
val myRamp = java.lang.Long.getLong("ramp", 0L)
setUp(scn.inject(rampUsers(nbUsers).during(myRamp.seconds)))

// Of course, passing a String is just as easy as:

JAVA_OPTS="-Dfoo=bar"

val foo = System.getProperty("foo")

Upvotes: 3

Dmitri T
Dmitri T

Reputation: 168247

The easiest way is going for Java system properties, for example if you have workload model defined as:

setUp(scn.inject(atOnceUsers(1)).protocols(httpProtocol))

if you change it from hard-coded to dynamic reading of the system property like:

setUp(scn.inject(atOnceUsers(Integer.parseInt(System.getProperty("userCount")))).protocols(httpProtocol))

you will be able to pass the desired number of users dynamically via -D command-line argument like:

gatling.bat -DuserCount=5 -s computerdatabase.BasicSimulation

More information: Gatling Installation, Verification and Configuration - the Ultimate Guide

Upvotes: 1

Related Questions