如何在加特林中将值从一个场景传递到另一个场景?

问题描述 投票:0回答:2

我有一些端到端的流程,我必须运行服务并将值传递到下一个场景。我可以打印场景内的值,但无法将它们用于下一个场景。

我尝试使用 SaveAs 保存值

val scn_Token1 ={ scenario("Token1")
    .exec(actionBuilder = http("Token1")
      .post("/getToken")
      .body(StringBody(bdy_Token)).asJson
      .check(status.is(200))
      .check(jsonPath("$.Token").exists)
      .check(jsonPath("$..Token")
        .find
        .saveAs("Token")
      )
      .check(jsonPath("$..id")
        .find
        .saveAs("mid")
      )
      .check(jsonPath("$..otp")
        .find
        .saveAs("otp")
      )
    )pause(tnk_token milliseconds)
  }


  val scn_Auth ={ scenario("Authentication")
    .exec(actionBuilder = http("Authentication")
      .post(authServiceUrl)
      .header("Token", "${Token}")
      .header("id", "${id}")
      .header("otp", "${otp}")
      .body(StringBody(bdy_Auth)).asJson
      .check(status.is(200)))
      .pause(tnk_Auth milliseconds)
  }



  setUp(
   scn_Token1.inject(nothingFor(dly_token_first seconds),rampUsers(ucnt_token_first) during (ramp_token_first seconds)).protocols(httpConfToken),
  scn_Auth.inject(nothingFor(dly_Auth seconds),rampUsers(ucnt_Auth) during (ramp_Auth seconds)).protocols(httpConf)
  ).maxDuration(test_duration minutes)

我遇到类似的错误

“httpRequest-2”执行失败:未定义名为“id”的属性

“httpRequest-2”执行失败:未定义名为“Token”的属性

我还尝试为第二个场景设置等待时间,它将在场景 1 完成后执行。但它仍然没有得到值。

请注意,我不希望在单个场景中合并令牌和身份验证,因为它具有不同的配置。值应该从一种场景传递到另一种场景。请告诉我这里出了什么问题?

gatling scala-gatling
2个回答
1
投票

Gattle 无法在用户之间传递数据 - 如果您需要在每个 scn_Auth 请求之前执行 scn_Token 以设置会话参数,只需将其包含在 scn_Token 中即可。

重新定义 scn_Auth 为

  val scn_Auth ={ scenario("Authentication")
.exec(scn_Token1)
.exec(actionBuilder = http("Authentication")
  .post(authServiceUrl)
  .header("Token", "${Token}")
  .header("id", "${id}")
  .header("otp", "${otp}")
  .body(StringBody(bdy_Auth)).asJson
  .check(status.is(200)))
  .pause(tnk_Auth milliseconds)
}

然后只为 scn_Auth 注入用户


0
投票

您找到运行上述场景的方法了吗?

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