I tried to create an bunch of objects via service using the ‘counterName’ variable of a repeat function.
But neither the “id” is calculated correctly nor the “name” is resolved (e.g. “Test_0”).
reasons are:
my ID has to start at 1
the name should be printed in the logs (e.g. “create object ‘Test_0’”)
I tried to access the session object but it seems not to be existing in repeat() but exec()
But inside exec() I can’t define variables
And because I’m a very beginner to Scala I got no clue how to handle it.
.repeat(5, “object_index”) {
val id = Integer.getInteger("${object_index}") + 1;
val name = “Test_${object_index}”
exec(
http(“create object '” + name + “’”)
.post("/objects")
.basicAuth(userName, userPassword)
.body("{" +
““id”: + id +,” +
““name”: “” + name + “”,” +
“}”)
.check(status.is(200)))
}
So the description of the http() can’t be changed during runtime because it is build once - understood.
I will try the SSP-Templates because my request bodies are getting bigger in near future.
It can be changed at runtime, but you have to understand what is evaluated at build time and what is evaluated at runtime.
Things evaluated at runtime are functions (usually Session => something) and EL (that are actually converted into functions).
In my above example, the request name “create object Test_${object_index}” is an EL that will be resolved every time a user sends this request.