11

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.

leo
  • 3,677
  • 7
  • 34
  • 46

3 Answers3

20

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)
leo
  • 3,677
  • 7
  • 34
  • 46
6

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

gmourier
  • 334
  • 3
  • 13
  • 1
    You can even get the base URL first from a system property: `val BaseUrl = System.getProperty("baseURL", "http://www.dummyurl.com")` – Rosberg Linhares Dec 19 '17 at 13:55
1

You can configure it yourself through various ways (System properties, environment variables, custom config files...) but this is not a Gatling built-in anymore.

Pierre DAL-PRA
  • 956
  • 5
  • 10