作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 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/
我是 Scala 和 gatling 的新手。如果使用 doIf 传递了先前的场景,我需要运行场景。 我的代码是: HTTP请求 object CompanyProfileRequest { val
我是一名优秀的程序员,十分优秀!