gpt4 book ai didi

scala - 如果使用 doIf 传递了上一个场景,则需要运行下一个场景

转载 作者:行者123 更新时间:2023-12-05 04:00:06 24 4
gpt4 key购买 nike

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

我的代码是:

HTTP请求

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 时)失败。

更好的方法是使用检查转换将 bool 值插入“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
)

现在您已经有了一个 bool session 变量(“OFFICE_NOT_FOUND”),您可以在您的 doIf 中使用它...

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

关于scala - 如果使用 doIf 传递了上一个场景,则需要运行下一个场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56696738/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com