[使用加特林将变量从json保存并获取到另一个场景中

问题描述 投票:1回答:1

我对scala使用加特林。我想检查金额+ 100。如何从saveAs(“ amount”)]获取金额并放入amount + 100

  private val getBeforeStatus = scenario("getBeforeStatus")
    .exec(http("GET method")
      .get("/get")
      .check(jsonPath("$.amount").ofType[Int].saveAs("amount")))

  private val post = scenario("post")
    .exec(http("POST method")
      .post("/post")
      .body(StringBody("{\"count\": 3}"))
      .check(status.is(200)))
    .exec(http("DELETE method")
      .delete("/delete/1")
      .check(status.is(200)))

  private val getAfterStatus = scenario("getAfterStatus")
    .exec(http("GET method")
      .get("/get")
      .check(jsonPath("$.amount").ofType[Int].is(amount + 100)))

  setUp(
    getBeforeStatus.inject(atOnceUsers(1)),
    post.inject(atOnceUsers(100)),
    getAfterStatus.inject(atOnceUsers(1)))
    .protocols(httpConf)
scala gatling
1个回答
0
投票
将金额值另存为模拟中的变量:

var amount: Int scenario("getBeforeStatus") .exec(http("GET method") .get("/get") .check(jsonPath("$.amount").ofType[Int].saveAs("amount"))) .exec{ session => amount = session("amount").as[Int] session }

然后,您需要“等待”,直到100个请求完成。临时解决方案是:

setUp( getBeforeStatus.inject(atOnceUsers(1)), post.inject(atOnceUsers(100)), getAfterStatus.inject( nothingFor(10 seconds), // enough time to end previous 100 requests atOnceUsers(1)) ) .protocols(httpConf)

© www.soinside.com 2019 - 2024. All rights reserved.