【问题标题】:Create account script创建帐户脚本
【发布时间】:2017-12-27 18:30:25
【问题描述】:

如何在 gatling 中创建 create account 脚本?

我没有找到任何示例说明如何从下面的代码中访问 post 响应以创建另一个请求。

 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))

在我的示例中,我想使用上面调用返回的令牌调用 /activate-accont/:token

【问题讨论】:

    标签: performance scala load-testing gatling scala-gatling


    【解决方案1】:

    希望这会奏效。

    .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}")
          ....)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-13
      • 1970-01-01
      • 2022-12-14
      • 2011-04-13
      • 1970-01-01
      • 2022-10-24
      • 2010-12-26
      相关资源
      最近更新 更多