There is an official documentation of Pebble templating in Gatling: https://gatling.io/2018/11/06/gatling-3-pebble-templating/
In the end of this you can see the code:
{% for child in children %}
{
"id": {{child.id}},
"name": "{{child.name}}"
}{% if loop.last %}{% else %},{% endif %}
{% endfor %}
It means that the children
variable is a list that contains a map with keys id
and name
But how to create such list and let Pebble know about it?
Currently I have a method for creation a list of maps:
def getArray(count: Integer): mutable.MutableList[Map[String, String]] = {
var array = mutable.MutableList[Map[String, String]]()
for (i <- 0 until count) {
array += Map(
"UniqueString" -> UUID.randomUUID.toString,
"RandomNumber" -> (Random.nextInt(10000) + 10000).toString,
"contentId" -> UUID.randomUUID.toString
)
}
array
}
And I have a feeder for it:
val elementsFeeder = Iterator.continually(Map(
"elements" -> getArray(documentsMultiple)
))
I feed it as usual:
def archive = repeat(1){
feed(elementsFeeder)
.exec(
.......
My pebble template looks like this:
[
{% for element in elements %}
Debugging info <element>: {{element}}
{"name": "{{element.UniqueString}}",
"value": "{{element.RandomNumber}}"}{% if loop.last %}{% else %},{% endif %}
{% endfor %}
]
But instead of name and value I see only empty space between quotes, when debugging line looks like this:
Debugging info <element>: Map(UniqueString -> 81a92aeb-3966-43ff-8c42-1e0e93ace3a4, RandomNumber0To100000 -> 11775, contentId -> 436701db-d66b-4819-b33e-3e455dbe19fc)
Even if I change the maps generation to convert them to Java's maps by adding .asJava
after a new Map declaration, I still see empty spaces and output like this:
Debugging info <element>: {UniqueString=119593c6-e526-4cca-a2d5-34d57bbfb22d, RandomNumber0To100000=16945, contentId=57385850-670b-484b-96e6-a1ec05c568ac}
Pebble is a java library and works with Java collections, not Scala ones.
There are some shortcomings as of Gatling 3.4.0:
Try using Java collections for now.