0
votes

I'm trying to dynamically generate headers for each request using a json feeder in gatling using the following code :

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class LoadTest extends Simulation {

val httpConf = http
.baseURL("http://example.com")

val tokensFeeder = jsonFile("Tokens.json");

val user1 = scenario("Download")
  feed(tokensFeeder)
  .exec(
    http("req")
     .post("/download")
     .headers("${header}")
     .body(StringBody("""{ "Device_Type":"iOS","Locations":[{"Latitude":"51.50719197","Longitude":"-0.127214091"}] }""")).asJSON
  )

setUp(
user1.inject(atOnceUsers(2)) 
).protocols(httpConf)
}

Where Tokens.json has data in the following format :

[
   {"header" : {"token" : "12234"}},
   {"header" : {"token" : "12235"}},
   {"header" : {"token" : "12236"}}
]

However i get the following error :

type mismatch;
found   : String("${header}")
required: Map[String,String]
11:23:07.862 [ERROR] i.g.c.ZincCompiler$ -          .headers("${header}")
11:23:07.864 [ERROR] i.g.c.ZincCompiler$ -                   ^
11:23:07.908 [ERROR] i.g.c.ZincCompiler$ - one error found
11:23:07.910 [ERROR] i.g.c.ZincCompiler$ - Compilation crashed
sbt.compiler.CompileFailed: null

It is my understanding that feeders contain a vector of maps so shouldn't "${header}" evaluate to {token : 12234} ?

Any help would be appreciated.

1

1 Answers

1
votes

Fixed with the following changes to headers :

.headers(Map("token" -> "${header.token}"))