Reputation: 5425
Disclaimer: I'm not that familiar with Scala, so I'm probably doing something stupid.
We're using Gatling for our performance tests. I'm currently trying to get it to submit a POST request to our API, using something like the following:
exec(http("post request")
.post("http://ourApi")
.body(
StringBody(
session => """{ "myContent": "value" }""" // 1
)
)
.asJSON
.check(status.is(200))
)
As you can see, I'm using an expression function for the StringBody
at the line labelled // 1
, which should be possible according to the Gatling documentation.
When I try to run that, however, I get a ZincCompiler error on that exact line:
type mismatch;
found : String("{ \"myContent\": \"value\" }")
required: io.gatling.core.validation.Validation[String]
Why is it expecting a Validation[String]
? In the documentation I only see strings as well...
Upvotes: 5
Views: 8020
Reputation: 170735
The page you linked says
Expression
Most Gatling DSL methods actually takes Expression[T] parameters, which is a type alias for Session => Validation[T].
How is it that one can also pass Strings and other values then?
The reason is that there are implicit conversions:
when passing a String, it gets automagically parsed turn them into Expressions thanks to Gatling EL compiler.
when passing a value of another type, it gets automagically wrapped into an Expression that will always return this static value.
So the problem is that the implicit conversion isn't getting triggered for some reason. From http://gatling.io/docs/2.2.2/session/validation.html#validation, you can try:
Add import io.gatling.commons.validation._
.
If that doesn't help, use Success("""{ "myContent": "value" }""")
explicitly.
Upvotes: 3