How to pass a parameter to the script

juno.yoon edited this page May 22, 2016 · 2 revisions

From nGrinder 3.2.3, a user can set the test parameter in the test configuration page which can be passed into test.

Parameter should be provided as 1~30 alphabet, numeric characters or underbar without spaces. When a test is executed, this are passed as a java parameter like –Dparam=value.

A script can take this by calling System.getProperty(“param”) and convert it to integer or boolean type whatever the script wants. However this is not detemined when a user valiadates the script. The param will be provided as a empty string, so a user should consider to call the System.getProperty with the default value like below.

System.getProperty(“param”, “defaultValue”)

If you’re using groovy and use the ngrinder-groovy dependency (above 3.2.3), you can use the several convenient utitlit methods to parse the param in the script.

net.grinder.util.GrinderUtils class contains following static methods.

  • getParam()
  • getParam(String)
  • getParamInt()
  • getParamLong()
  • getParamFloat()
  • getParamDouble()
  • getParamBoolean()

Whenever you need to get the param, you can call the one of above methods to get the param and parse it into the appropriate type.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.