8

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.

Karl Ivar Dahl
  • 1,023
  • 2
  • 11
  • 23

2 Answers2

20

From the documentation:

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

will do the trick.

Pierre DAL-PRA
  • 956
  • 5
  • 10
9

Thanks to the answer from Pierre, I have pieced this together:

val soap = 
    exec(_.set("cardNumber","1001"))
    .exec(http("SOAP Request")
    .post("/pl4/pto/ws3/WSReconstructionService")
    .body(ELFileBody("GetBlacklistStatus.xml")).asXML
    .basicAuth("user2", "pwd2")
    .check(status.is(200))
    )

For those like me that are not familiar with the underscore the following also seems to work:

val soap = 
    exec{session =>session.set("cardNumber","1001")}
    .exec(http("SOAP Request")
    .post("/pl4/pto/ws3/WSReconstructionService")
    .body(ELFileBody("GetBlacklistStatus.xml")).asXML
    .basicAuth("user2", "pwd2")
    .check(status.is(200))
    )
Community
  • 1
  • 1
Karl Ivar Dahl
  • 1,023
  • 2
  • 11
  • 23