首页 > 解决方案 > 加特林序列场景

问题描述

我正在尝试使用gatling,但我遇到了问题。

1-我有一个场景,执行POST请求获取令牌列表并将所有令牌保存在csv

2-我创建了另一个执行请求的场景,GET但我需要一个令牌来验证每个请求

我的问题是在执行我的第一个场景之前我的文件不存在并且我有以下错误:

Could not locate feeder file: Resource user-files/resources/token.csv not found

我的代码:

方案 1:

val auth_app = scenario("App authentication")
  .exec(http("App Authentication")
  .post("/token")
  .header("Content-Type", "application/x-www-form-urlencoded")
  .formParamSeq(Seq(("grant_type", "password"), ("client_id", clientID), ("client_secret", clientSecret)))
  .check(jsonPath("$.token").saveAs("token")))
  .exec(session => {
  val token_data = new File(token_file_path)
  if(token_data.exists()){
    val writer = new PrintWriter(new FileOutputStream(new File(token_file_path), true))
    writer.write(session("access_token").as[String].trim)
    writer.write("\n")
    writer.close()
  }
  else {
    val writer = new PrintWriter(new FileOutputStream(new File(token_file_path), true))
    writer.println("AccessToken")
    writer.write(session("access_token").as[String].trim)
    writer.write("\n")
    writer.close()
  }
  session
})

方案 2:

val load_catalog = scenario("Load catalog")
  .exec(http("Load catalog")
  .get("/list")
  .headers(Map("Content-Type" -> "application/json", "Authorization Bearer" -> "${AccessToken}")))
  .feed(csv(token_file_path).random)

我的设置:

setUp(
auth_app.inject(atOnceUsers(10)).protocols(httpProtocol),
load_catalog.inject(nothingFor(120 seconds), atOnceUsers(10)).protocols(httpProtocol)
)

是否有可能有一个带加特林的动态馈线?

标签: scalagatlinggatling-plugin

解决方案


推荐阅读