0

I'm trying to use gatling and I have a problem.

1- I have one scenario that exec POST request for getting a list of tokens and save all tokens in csv

2- I create another scenario that exec GET request but I need a token for auth each request

My problem is before executing my first scenario my file doesn't exist and I have this following error:

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

My code :

Scenario 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
})

Scenario 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)

My setup :

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

Is it possible to have a dynamic feeder with gatling ?

M.Hol
  • 365
  • 2
  • 4
  • 15
  • Have you taken a look at the answer here ? [Gatling - dynamic feed selection](https://stackoverflow.com/questions/24533162/gatling-dynamic-feed-selection) ? You can use a [doIf](https://gatling.io/docs/2.3/general/scenario#doif) execution block, if doSwitch doesn't suit – anasmi Aug 08 '19 at 12:23
  • me mindful of the scenario that you're trying to replicate. Why generate all the access tokens before making any of the requests that use them? Depending on your application under test, it might be more correct to combine these into a single scenario where a user just gets its token then logs in. – James Warr Aug 08 '19 at 23:18

0 Answers0