I want to set the StringBody value in a variable:
exec(session => {session.set("searchBody", """{"productId":"${productID}","category":"${category}"}""")})
Variables ${productID} and ${category} exist. And I want to use the value as parameter of the function StringBody:
http("/products")
.post(appURL + "/search")
.headers(jsonHeader)
.body(StringBody("${searchBody}")).asJSON
But It doesn't work as expected. I am getting the following error:
i.g.h.a.ResponseProcessor - Request '/products' failed:status.find.is(200), but actually found 403
Why are not the variables printed in the string for variable searchBody?
UPDATE:
I am trying that:
val search= exec(repeat(products.size, "n"){
feed(products.circular)
.uniformRandomSwitch( //5
exec(session => {session.set("searchBody", """{"productId":"${productID}","minPrice":"${minPrice}"}""")}),
exec(session => {session.set("searchBody", """{"productId":"${productID}","category":"${category}"}""")})
)
.exec(
http("/products")
.post(appURL + "/search")
.headers(jsonHeader)
.body(StringBody("${searchBody}")).asJSON
.check(status.is(200), responseTimeInMillis.lessThan("${expectedResponseTime}"))
)
})
I want to send different type of requests balancing uniformly and I don't want to duplicate the exec part. The endpoint is always the same and only the body is different.
Forbiddenso either you are lacking some authorization or your are trying to make something you should not do. To verify if request is sent correctly you can change logging level (see: Gatling Debugging) toTRACEthis way you will get request and response printed to console. But I think that your problem is double interpolation. You are adding strings with gatling el placeholders into session and than try to read that with gatling el placeholder again, this wont work. Try to build StringBody with session expression - Mateusz Gruszczynski