# ConfigFactory and config files for environment specific test runs

**URL:** <https://community.gatling.io/t/configfactory-and-config-files-for-environment-specific-test-runs/5997>\
**Category:** Gatling (Open-Source)\
**Created:** [February 23, 2021, 9:46pm UTC](https://community.gatling.io/t/configfactory-and-config-files-for-environment-specific-test-runs/5997 "2021-02-23T21:46:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_Eales](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@Jason\_Eales](https://community.gatling.io/u/Jason_Eales)\
**Post date:** [February 23, 2021, 9:46pm UTC](https://community.gatling.io/t/configfactory-and-config-files-for-environment-specific-test-runs/5997/1 "2021-02-23T21:46:21Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [February 23, 2021, 9:52pm UTC](https://community.gatling.io/t/configfactory-and-config-files-for-environment-specific-test-runs/5997/2 "2021-02-23T21:52:17Z")

</div>

Use [Java System properties](https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html). You can pass them from the command line .\gatling.bat --simulation “api.private” -Dfoo=bar

---

<div class="post-metadata">

**Author:** ![Jason\_Eales](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@Jason\_Eales](https://community.gatling.io/u/Jason_Eales)\
**Post date:** [February 23, 2021, 10:27pm UTC](https://community.gatling.io/t/configfactory-and-config-files-for-environment-specific-test-runs/5997/3 "2021-02-23T22:27:47Z")

</div>

Thanks Stephane ill give it a try 👍

---

<div class="post-metadata">

**Author:** ![Jason\_Eales](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@Jason\_Eales](https://community.gatling.io/u/Jason_Eales)\
**Post date:** [February 23, 2021, 11:47pm UTC](https://community.gatling.io/t/configfactory-and-config-files-for-environment-specific-test-runs/5997/4 "2021-02-23T23:47:41Z")

</div>

@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](https://gatling.io/docs/current/cookbook/passing_parameters/)

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [February 24, 2021, 6:40am UTC](https://community.gatling.io/t/configfactory-and-config-files-for-environment-specific-test-runs/5997/5 "2021-02-24T06:40:37Z")

</div>

Right, for the bundle, you have to set the JAVA\_OPTS env var with the System props you want, eg -Dfoo=bar

---

<div class="post-metadata">

**Author:** ![Sri\_Harsha\_G](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@Sri\_Harsha\_G](https://community.gatling.io/u/Sri_Harsha_G)\
**Post date:** [March 4, 2021, 3:52pm UTC](https://community.gatling.io/t/configfactory-and-config-files-for-environment-specific-test-runs/5997/6 "2021-03-04T15:52:35Z")

</div>

Hi,  
If you use gradle plugin for gatling it will be helpful  
[https://github.com/gatling/gatling-gradle-plugin](https://github.com/gatling/gatling-gradle-plugin)

Setup gradle as the build tool instead of using bat file for execution

---

<div class="post-metadata">

**Author:** ![Jason\_Eales](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@Jason\_Eales](https://community.gatling.io/u/Jason_Eales)\
**Post date:** [March 4, 2021, 9:55pm UTC](https://community.gatling.io/t/configfactory-and-config-files-for-environment-specific-test-runs/5997/7 "2021-03-04T21:55:14Z")

</div>

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**

---

<div class="post-metadata">

**Author:** ![Sri\_Harsha\_G](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@Sri\_Harsha\_G](https://community.gatling.io/u/Sri_Harsha_G)\
**Post date:** [March 5, 2021, 2:52pm UTC](https://community.gatling.io/t/configfactory-and-config-files-for-environment-specific-test-runs/5997/8 "2021-03-05T14:52:49Z")

</div>

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")
