我尝试使用json feed使用以下代码为每个请求动态生成标头:
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)
}
Tokens.json的数据格式如下:
[
{"header" : {"token" : "12234"}},
{"header" : {"token" : "12235"}},
{"header" : {"token" : "12236"}}
]
但是我收到以下错误:
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
据我所知,馈线包含地图矢量,所以不应该&#t;#34; $ {header}"评价为{token:12234}?
任何帮助都将不胜感激。
答案 0 :(得分:1)
修正了标题的以下更改:
.headers(Map("token" -> "${header.token}"))