【发布时间】:2021-07-31 10:43:18
【问题描述】:
有没有办法像这样创建动态场景?下面的代码给出错误未找到:类型场景定义 my_test():场景 = {。我认为场景不需要导入
def my_test() : scenario = {
if(condition)
scenario(build_name)
.exec(http("post"+build_name+"content")
.post(end_point_url)
.header("Authorization", "Bearer "+ token)
.body(RawFileBody(input_file_path)).asXml
.check(status is 200))
else
scenario(build_name)
.exec(http("post"+build_name+"content")
.post(end_point_url)
.header("Authorization", "Bearer "+ token)
.body(RawFileBody(input_file_path)).asJson
.check(status is 200))
}
setUp(my_test()
.inject(
nothingFor(2 seconds),
constantUsersPerSec(users).during(10 seconds)
))
.assertions(
global.responseTime.mean.lt(threshold = mean_response_time),
global.successfulRequests.percent.gte(minSuccessPercent)
)
.protocols(httpConf)
.assertions(
forAll.responseTime.max.lt(threshold = responseTime)
)
编辑 当我尝试使用
def my_test() = {
if(condition)
scenario(build_name)
.exec(http("post"+build_name+"content")
.post(end_point_url)
.header("Authorization", "Bearer "+ token)
.body(RawFileBody(input_file_path)).asXml
.check(status is 200))
else
scenario(build_name)
.exec(http("post"+build_name+"content")
.post(end_point_url)
.header("Authorization", "Bearer "+ token)
.body(RawFileBody(input_file_path)).asJson
.check(status is 200))
}
出现以下错误
17:10:01.582 [main][ERROR][ZincCompiler.scala:151] i.g.c.ZincCompiler$
- ... .scala:132:2: method my_test has return statement; needs result type
return scenario(build_name)
^ 17:10:01.645 [main][ERROR][ZincCompiler.scala:122] i.g.c.ZincCompiler$ - one error found 17:10:01.648 [main][ERROR][ZincCompiler.scala:219] i.g.c.ZincCompiler$ - Compilation crashed sbt.internal.inc.CompileFailed: null
at sbt.internal.inc.AnalyzingCompiler.call(AnalyzingCompiler.scala:242)
编辑
感谢所有为这篇文章做出贡献的人。我必须使用导入语句 io.gatling.core.structure.{PopulationBuilder, ScenarioBuilder} 将场景修改为 ScenarioBuilder,如提到的 here
【问题讨论】:
-
有例子解释如何将场景设置为变量stackoverflow.com/questions/61167486/…
-
请提供完整的代码,而不是部分代码。否则,无法判断您的代码错误是什么。