简体   繁体   中英

Dynamic header in gatling load test

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.

修复了标头的以下更改:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM