0

How can I create a create account script in gatling?

I do not find any example of how can I access the post response from the code bellow to create another request.

 val httpConf = http
    .baseURL("http://localhost:3030") // Here is the root for all relative URLs
    .acceptHeader("application/json") // Here are the common headers

  val orderRefs = Iterator.continually(
    // Random number will be accessible in session under variable "OrderRef"
    Map("OrderRef" -> Random.nextInt(Integer.MAX_VALUE))
  )

  val scn = scenario("Create Account") // A scenario is a chain of requests and pauses
    .feed(orderRefs) 
    .exec(http("Create Account Request")
      .post("/account-request")
        .body(StringBody("""{"password":"pw${OrderRef}","email":"email${OrderRef}@test.com","firstName":"Name${OrderRef}"}""")).asJSON)

  setUp(scn.inject(atOnceUsers(10)).protocols(httpConf))

In my example I want call /activate-accont/:token with a token returned by the call above

Victor
  • 8,309
  • 14
  • 80
  • 129

1 Answers1

0

Hope this will work.

.exec(http("Create Account Request")
      .post("/account-request")
      .body(StringBody("""{"password":"pw${OrderRef}","email":"email${OrderRef}@test.com","firstName":"Name${OrderRef}"}""")).asJSON
      .check(jsonPath("$.Token")).saveAs("myToken")) //Assuming you are getting Token with $.Token
      )

.exec(http("Activate Account")
      .post("/activate-accont/${myToken}")
      ....)
Peter
  • 855
  • 2
  • 15
  • 35