I want to configure the base url of my gatling simulation in the configuration file. So that I can easy switch between test and live system.
I works fine when I configure it in the simulation-scala file with:
val httpConf = http
.baseURL("http://computer-database.herokuapp.com")
If I remove the line above and configure it in the config (gatling.conf) file with:
gatling {
http {
baseUrls = "http://localhost8080/baserate"
...
I get the following error and my scenario does not work because the base url is empty.
09:57:26.352 [ERROR] i.g.c.c.GatlingConfiguration$ - Your gatling.conf file is outdated, some properties have been renamed or removed.
Please update (check gatling.conf in Gatling bundle, or gatling-defaults.conf in gatling-core jar).
Enabled obsolete properties:'gatling.http.baseUrls' was removed, use HttpProtocol.
Is it still possible in the current version of gatling to configure the base url outside of the
My version is the gatling-maven-plugin:2.1.2.
I solved this by creating a application.properties file in /test/resources/ with
baseUrl=http://www.example.com
I changed my simulation like this:
import com.typesafe.config._
class BasicSimulation extends Simulation {
val conf = ConfigFactory.load()
val baseUrl = conf.getString("baseUrl")
val httpConf = http.baseURL(baseUrl)
You can also create a singleton object and expose it in any gatling simulation class.
Imagine a singleton object called Configuration in Configuration.scala like this one :
object Configuration {
val BaseUrl = "http://www.dummyurl.com"
}
This should reduce code in your simulation class
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
class MySimulation extends Simulation {
val HttpConf = http
.baseURL(Configuration.BaseUrl)
...
}
Just resolve package definitions and imports if needed and voila.
Note: Since val means immutable property we should name it with a first uppercase letter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With