Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying a request body doing a Gatling POST

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?

like image 718
Mike Malloy Avatar asked Oct 10 '14 01:10

Mike Malloy


People also ask

How to send post requests which contain random data in Gatling?

In this Gatling tutorial, we show how t send post requests which contain random data in the StringBody (). In most performance testing scenarios, you want to randomize the data that is sent as post request to simulate different sessions. For this, we can make use of feeders which read data from CSV files or plain text.

How to put request bodies in an external file in Gatling?

Gatling provides a way to put the request bodies in an external file where values of JSON attributed will be replaced by a placeholder called Gatling ELString. Following is the syntax for the same: .body (RawFileBody (path: Expression [String])) // here argument path is the location of a file that will be uploaded and contains the data.

What is the use of rawfilebody method in Gatling?

This method is useful for the request with small request bodies. //here argument string can be a raw String, a Gatling EL String, or an Expression function. RawFileBody method enables you to send the request bodies from an external raw file. Gatling will read the data from the file and inject it into the simulation without putting it in the memory.

How to execute a HTTP request in Gatling?

HTTP requests have to be passed to the exec () method in order to be attached to the scenario and be executed. Gatling provides built-ins for the most common methods. Those are simply the method name in minor case. Gatling also support relative urls, see baseUrl.


1 Answers

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"}"""))
like image 83
Stephane Landelle Avatar answered Nov 15 '22 06:11

Stephane Landelle