Basic example for adding a value to the Gatling session needed

Karl Ivar Dahl picture Karl Ivar Dahl · Aug 4, 2015 · Viewed 21.3k times · Source

I want to be able to POST a SOAP request with a configurable value found in my Gatling source. Therefore, I have the following XML ELFileBody stored in the file "request.xml"

...
   <rec:cardNumber>${cardNumber}</rec:cardNumber>
...

I understand that the variable cardNumber must be added to session. There is plenty documentation stating that this is necessary. However, I have found no complete examples on how this is done correctly in the context of an execution.

Given the following Gradle 2.1 code:

    class GetBlacklistStatus extends Simulation {
      val cardNumber="12345"

      object GetBlacklistStatus {
        val soap = exec(http("SOAP Request")
            .post("/myservice")
            .body(ELFileBody("request.xml")).asXML
            .basicAuth("testUSER", "testPASSWORD")
            )
      }
      val httpConf = http
        .baseURL("http://localhost:8080")
        .proxy(Proxy("localhost", 8888))
        .userAgentHeader("Gradle TEST")

      val users= scenario("user").exec(GetBlacklistStatus.soap)

      setUp(
        users.inject(rampUsers(10) over (10 seconds))
      ).protocols(httpConf)
    }

How can I put the declared value cardNumber into the session before the POST?

I am aware that I could use a mechanism such as a feeder to move values into the session for me, but I want to do it directly and hopefully learn something in the process.

Answer

Pierre DAL-PRA picture Pierre DAL-PRA · Aug 4, 2015

From the documentation:

.exec(_.set("cardNumber", "12345"))

will do the trick.