9

I'm a fresh newbie to Gatling. I'm trying to send a POST message to an HTTP API using Gatling. I tried the following:

package app.basic
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class basicPost extends Simulation {
  val headers_10 = Map("Content-Type" -> """application/json""")
  object Post {
      // repeat is a loop resolved at RUNTIME
      val post = repeat(50) { 
      exec(http("Post Data")
          .post("/data")
          .queryParam("""size""", "10"))
          .headers(headers_10)
          .body("""{"id1":"0000000000"}""")
          .pause(1)
  }
  }
  val httpConf = http.baseURL("http://amazonperf-env.elasticbeanstalk.com")   
  val users = scenario("Users").exec(Post.post)
  setUp(
    users.inject(rampUsers(1000) over (10 seconds))
  ).protocols(httpConf)
}

However, I get this error when compiling: value body is not a member of io.gatling.core.structure.ChainBuilder possible cause: maybe a semicolon is missing before `value body'?

How do I specify the body of the message that I want to send?

Mike Malloy
  • 1,520
  • 1
  • 15
  • 19

6 Answers6

20

This is old Gatling 1 syntax (Gatling 1 is deprecated and no longer maintained).

Please read the documentation.

In you case, you'd get something like:

.body(StringBody("""{"id1":"0000000000"}"""))
Stephane Landelle
  • 6,990
  • 2
  • 23
  • 29
1

As per current documentation, it is like this:

.body(StringBody("""{ "id1":"0000000000" }""")).asJson

Also remove extra closing bracket at:

.queryParam("""size""", "10"))

Place the closing bracket correctly like below:

.pause(1))
Anurag
  • 45
  • 7
0

Moreover, it looks like you closed your exec blog a bit too fast, just after queryParam("""size""", "10").

The closing parenthesis should after .body(...), not after .queryParam(...).

Pierre DAL-PRA
  • 956
  • 5
  • 10
0

you could use the method formParam(key: Expression[String], value: Expression[Any]) to post the message to the API.

jmdodo
  • 1
0

Try to send request body as follows

.body(StringBody("""{
                           "name": "morpheus",
                           "job": "leader"
                       } """)).asJson)
  • Welcome to Stack Overflow. Please [edit] your answer to explain how it answers the question, so that it is useful to users with similar issues. Code-only answers are discouraged on Stack Overflow because they don't explain how it solves the problem. – FluffyKitten Oct 04 '20 at 01:59
0

You can try something like this:

.body(RawFileBody("test-data/your-request-body.json"))

Here 'test-data' is present in 'resources' folder.

horizon7
  • 1,113
  • 14
  • 18