如何从供稿器获取随机值以在加特林中使用in标头

时间:2018-09-21 08:12:36

标签: scala gatling

我在标头中使用了1000个令牌的CSV,每种情况下都可以使用任何随机令牌。对于该场景中的所有获取和发布请求,该随机令牌应保持相同。以下是CSV文件的示例数据。

令牌

令牌token1tewq

令牌token2cbvj

依此类推,直到1000行

我要执行的方案如下。

  1. 在标头中使用随机令牌(来自CSV)命中get API。
  2. 暂停2秒。
  3. 使用第1步中获取的具有相同令牌的正文来匹配发布API。
  4. 使用与步骤1中相同的令牌来使用相同的API。

我尝试使用以下代码进行操作,但是无法正常工作。

val tokencsv = csv("test.csv").random
val httpConf = http.baseURL("http://myApiUrl")
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") // Here are the common headers
    .doNotTrackHeader("1")
    .acceptLanguageHeader("en-US,en;q=0.5")
    .acceptEncodingHeader("gzip, deflate")
    .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")

val userFeed = feed(tokencsv)
      .exec(http("Get all feeds")
      .get("url1")
      .headers(Map("Content-Type" -> "application/json","Authorization" -> "${token}")))
      .pause(2)
      .exec(http("Post a feed")
      .post("url2")
      .body(StringBody("""{"type":2, "images":["http://imageurl.jpg"],"text":"lorem ipsum", "data_id":12}""")).asJSON
      .headers(Map("Content-Type" -> "application/json","Authorization" ->  "${token}")))
      .pause(1)
      .exec(http("Reloading page after posting the feed").get("url1")
      .headers(Map("Content-Type" -> "application/json","Authorization" -> "${token}")))

val socialFeedGetAll = scenario("social feed").exec(userFeed)
setUp(socialFeedGetAll.inject(constantUsersPerSec(10) during(60 seconds)).protocols(httpConf))

0 个答案:

没有答案