Dear Gatling Team,
Help please …
How to save json response in new csv file or how to save response is public variable so that i can use for next API to pass as request paramater(API chaning)
So for i tried with my code:
package dealerUserService_userInfo
import hyke_BaseConfig.BaseSimulation
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import io.gatling.core.structure.ChainBuilder
class fetch_user_info extends BaseSimulation {
//define feeder
val csvfeeder = csv(fileName = “data/UserLoginwithEmail.csv”)
//Define Request
def User_login_with_emial_method(): ChainBuilder = {
feed(csvfeeder)
.exec(http(requestName = “User Login with Email”)
.post(url = “/dealer/user/v1/login”)
.body(StringBody(
“”"
{“emailId”: “${emailId}” ,“password”: “${password}”}
“”“.stripMargin)).asJson
.check(jsonPath(path = “$.data.auth.token”).saveAs(key = “numberIDs”))
.check(bodyString.saveAs(“RESPONSE_DATA”)))
.exec(session => {
println(“Some Restful Service Response Body:”)
println(session(“RESPONSE_DATA”).as[String])
session
})
//Save variable numberIDs into the csv file
.foreach(”${numberIDs}", “id”) {
exec(session => {
numberIDs_writer.println(session(“id”).as[String])
session
})
}
}
//Variables to store the extracted values of the response
var numberIDs : Seq[String] = _
//Java Writer
val numberIDs_writer = {
val fos = new java.io.FileOutputStream(“data/numbersIDs.csv”)
new java.io.PrintWriter(fos,true)
}
//setup scenario
val scn = scenario(scenarioName = “Trying to generate OTP for Mobile registered Users”)
.exec(User_login_with_emial_method())
//inject User -Load profile
setUp(scn.inject(atOnceUsers(users = 1))
//rampusers(500) over (30 minutes).maxDuration(3600 seconds)
.protocols(httpConf))
}
Error message :
22:07:51.099 [ERROR] i.g.a.Gatling$ - Run crashed
java.io.FileNotFoundException: data/numbersIDs.csv (No such file or directory)
Note : but i have used same path for CSV feeder for data driven its working file.
Please please can you guide me how to save response in new CSV file or in Public variable how to store values in public variable.