Is there any way to create dynamic scenario perhaps like this? below code giving error not found: type scenario def my_test() : scenario = {. I think import is not required for scenario
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)
)
EDIT When I tried with
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))
}
it is giving following error
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)
EDIT
Thanks for all who contributed to this post. I had to modify scenario to ScenarioBuilder with import statement io.gatling.core.structure.{PopulationBuilder, ScenarioBuilder} added as mentioned here
As the compiler is saying, scenario
is unknown (not actually a Gatling type by the way) and moreover it is not the type returned by your method.
You could either drop the return type and let the compiler infer it for you or write the proper return type.
EDIT: Zinc compiler used by Gatling needs an explicit return type, so you have to find out the right type (maybe ScenarioBuilder
).