-1

So I know we cannot perform DSL operations in before/after of a Gatling simulation, but in 3.0 it does not appear to work at all. If I run the simulation I don't see a print line and I do not reach a break point on the prints. I am using Intellij. I must be missing something obvious, any help would be appreciated

My Simulation:

    import io.gatling.core.Predef._
import io.gatling.http.Predef._

class Sample extends Simulation {

    val httpProtocol = http
        .baseUrl("https://www.google.com")
        .inferHtmlResources()

    val headers_0 = Map(
        "accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "accept-encoding" -> "gzip, deflate, br",
        "accept-language" -> "en-US,en;q=0.9",
        "cache-control" -> "max-age=0",
        "upgrade-insecure-requests" -> "1",
        "user-agent" -> "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36")

    def before = {
        println("In the Before")
    }

    def after = {
        println("All done!")
    }

    val scn = scenario("Sample")
        .exec(http("request_0")
            .get("/")
            .headers(headers_0)
    )

    setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

I am using a object to run the simulation. Included below in case it's relevant:

import io.gatling.app.Gatling
import io.gatling.core.config.GatlingPropertiesBuilder

object temp {

  def main(args: Array[String]): Unit = {
    val simulation = classOf[Sample].getName
    val runner = new GatlingPropertiesBuilder

    runner.simulationClass(simulation)
    Gatling.fromMap(runner.build)

  }

}
adambsg
  • 131
  • 2
  • 9

1 Answers1

0

Problem in chair, not in computer... solution below. Credit to Stéphane Landelle for solution.

import io.gatling.core.Predef._
import io.gatling.http.Predef._

class Sample extends Simulation {

    val httpProtocol = http
        .baseUrl("https://www.google.com")
        .inferHtmlResources()

    val headers_0 = Map(
        "accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "accept-encoding" -> "gzip, deflate, br",
        "accept-language" -> "en-US,en;q=0.9",
        "cache-control" -> "max-age=0",
        "upgrade-insecure-requests" -> "1",
        "user-agent" -> "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36")

    before {
        println("In the Before")
    }

    after {
        println("All done!")
    }

    val scn = scenario("Sample")
        .exec(http("request_0")
            .get("/")
            .headers(headers_0)
    )

    setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
adambsg
  • 131
  • 2
  • 9