如果使用 doIf 传递上一个场景,则加特林需要运行下一个场景



我是Scala和gatling的新手。 如果使用 doIf 传递以前的场景,我需要运行 Scenaio。

我的代码是:

HttpRequest

object CompanyProfileRequest {
val check_company_profile: HttpRequestBuilder = http("Create Company 
 Profile")
.get(onboarding_url_perf + "/profile")
.headers(basic_headers)
.headers(auth_headers)
.check(status.is(404).saveAs("NOT_FOUND"))

val create_company_profile: HttpRequestBuilder = http("Create Company 
 Profile")
.post(onboarding_url_perf + "/profile")
.headers(basic_headers)
.headers(auth_headers)
.body(RawFileBody("data/company/company_profile_corporation.json")).asJson
.check(status.is(200))
.check(jsonPath("$.id").saveAs("id"))
 }

场景类是:-

 object ProfileScenarios {
  val createProfileScenarios: ScenarioBuilder = scenario("Create profile 
  Scenario")
  .exec(TokenScenario.getCompanyUsersGwtToken)
  .exec(CompanyProfileRequest.check_company_profile)
  .doIf(session => session.attributes.contains("NOT_FOUND")) {
   exec(CompanyProfileRequest.create_company_profile).exitHereIfFailed
   }
 }

模拟是:-

      private val createProfile = ProfileScenarios
     .createProfileScenarios
     .inject(constantUsersPerSec(1) during (Integer.getInteger("ramp", 1) 
     second))
     setUp(createProfile.protocols(httpConf))

每当我运行此模拟时,我都无法检查此条件:-

.doIf(session => session.attributes.contains("NOT_FOUND"((

任何帮助都非常感谢。

问候维克拉姆

我能够让你的例子工作,但这里有一个更好的方法......

使用的主要问题

.check(status.is(404).saveAs("NOT_FOUND"))

.doIf(session => session.attributes.contains("NOT_FOUND"))

实现条件切换是,您现在有一个检查,该检查将导致check_company_profile在确实不应该失败时(例如,当您获得 200 时(。

更好的方法是使用检查转换将布尔值插入到"NOT_FOUND"变量中。这样,当 office 存在时,您的check_company_profile操作仍然可以通过,并且 doIf 构造可以只使用 EL 语法,并且更清楚地了解它执行的原因。

val check_company_profile: HttpRequestBuilder = http("Create Company Profile")
  .get(onboarding_url_perf + "/profile")
  .headers(basic_headers)
  .headers(auth_headers)
  .check(
    status.in(200, 404), //both statuses are valid for this request
    status.transform( status => 404.equals(status) ).saveAs("OFFICE_NOT_FOUND") //if the office does not exist, set a boolean flag in the session
  )

现在你有一个布尔会话变量("OFFICE_NOT_FOUND"(,你可以在你的doIf中使用它。

.doIf("${OFFICE_NOT_FOUND}") {
   exec(CompanyProfileRequest.create_company_profile).exitHereIfFailed
}

相关内容

最新更新