Hi
My setup
- Visual Studio Code with the Scala extension
- Gatling 3.4 (Open-Source)
- Start tests using the following command line
- I use Powershell to run this command
- .\gatling.bat --simulation “api.private”
The question
I would like to have more information on how I setup my Gatling so that, from the command line i can run my tests against a particular environment (eg. Acceptance, Test, Dev)
Through some investigation I have found the ConfigFactory and have managed to use it with a new custom config file named accp.config.
However Im unable to supply this config file as part of the command line options!
https://gatling.io/docs/current/general/configuration/#zip-bundle-command-line-options
What is a good approach to use to get this to work the way I expect?
Use Java System properties. You can pass them from the command line .\gatling.bat --simulation “api.private” -Dfoo=bar
Thanks Stephane ill give it a try
@Stéphane Landelle
nah mate that does not work.
In the Powershell command typed .\gatling.bat --simulation “api.private” -Dfoo=bar
and added the following lines to me code
var h = System.getProperty(“foo”)
println(“h=” + h)
when i ran it i get the message
Warning: Unknown option -Dfoo=bar
h=null
The test ran successfully but the “foo bar” part did not pull the data from the command line
any ideas as to what im doing incorrectly?
PS: I also tried this and it too did not work
Passing Parameters – Gatling Open-Source Load Testing Documentation
Right, for the bundle, you have to set the JAVA_OPTS env var with the System props you want, eg -Dfoo=bar
Hi,
If you use gradle plugin for gatling it will be helpful
https://github.com/gatling/gatling-gradle-plugin
Setup gradle as the build tool instead of using bat file for execution
Hi
I have managed to get it working in PowerShell.
Param(
[Parameter(Mandatory=$true)]
[ValidateSet(“PROD”, “ACCP”, “TEST”)]
$environment
)
Set-Variable JAVAOPTS_ENV_PARAM -Option Constant -Value ([string]"-Denvironment=")
$javaoptsenv = $JAVAOPTS_ENV_PARAM + $environment
Set-Item ENV:JAVA_OPTS $javaoptsenv
$simname = "test.sim"
$gatsim = ".\gatling.bat --simulation $testsim"
&cmd /c $gatsim
ok… looks good. but if you want to have a proper implementation, I would prefer using gradle build tool and gatling gradle plugin
Build.gradle
sourceSets{
gatling {
resources.srcDir “src/gatling/resources/”
scala.srcDir “src/gatling/simulations/”
scala.srcDir “src/gatling/java”
scala.srcDir “src/gatling/scala”
}
}
gatling {
toolVersion = ‘3.3.1’
logLevel = ‘WARN’
jvmArgs = [’-server’, ‘-Xmx4G’,
‘-XX:+UseG1GC’, ‘-XX:MaxGCPauseMillis=30’,
‘-XX:G1HeapRegionSize=16m’,
‘-XX:InitiatingHeapOccupancyPercent=75’,
‘-XX:+ParallelRefProcEnabled’,
‘-XX:+PerfDisableSharedMem’,
‘-XX:+AggressiveOpts’,
‘-XX:+OptimizeStringConcat’,
‘-XX:+HeapDumpOnOutOfMemoryError’]
systemProperties = [‘file.encoding’: ‘UTF-8’]
simulations = {
include “/*.scala"
include "//.scala”
}
}
Simulation : fetching variables from commandline args and parameters
val env = System.getProperty(“env”)
val envConf = ConfigFactory.load(“conf/environment.conf”)
val baseURL = envConf.getString(s"$env.baseURL")
val authUser= envConf.getString(s"$env.user")
val authPassword = envConf.getString(s"$env.password")