I am new to gatling and scala. I am trying to do following thing:-
test.json:
[
{
"code": "AML",
"data": "aaasdfgghh"
},
{
"code": "ABC",
"data": "aaasdfgghh"
},
{
"code": "SDF",
"data": "aaasdfgghh"
}
]
Now i want to read this json key/value in loop. Currently i am doing like this:
Request Body and feeder:-
val jsonFileFeederFundsDoc: SourceFeederBuilder[Any] =
jsonFile("test.json").circular
//Saves locally and to S3
val upload_fund_s3: HttpRequestBuilder =
http("upload Fund docs Locally")
.post(onboarding_url_perf + "/document/passfort")
.headers(basic_headers)
.headers(auth_headers)
.body(StringBody(
"""{
"code": "${code}",
"data": "${data}"
}"""
)).asJson
.check(status.is(200))
.check(jsonPath("$.id").saveAs("id"))
And My Scenario is :-
val newFundScenario: ScenarioBuilder = scenario("Company Fund Scenarios exists")
.exec(TokenScenario.getCompanyUsersGwtToken).exitHereIfFailed
.exec(CompanyProfileRequest.check_company_exists).exitHereIfFailed
.doIf("${COMPANY_NOT_FOUND}") {
exec(CompanyProfileRequest.create_company_fund_profile).exitHereIfFailed
}
.feed(UploadFundDocsInPassfort.jsonFileFeederFundsDoc)
.exec(UploadFundDocsInPassfort.upload_fund_s3).exitHereIfFailed
.exec(UploadFundDocsInPassfort.upload_fund_passfort).exitHereIfFailed
.exec(OfficersRequest.create_director).exitHereIfFailed
And my Test Simulation is :
class TestCompanySimulation extends Simulation {
private val generalCompanyTestCases = GeneralCompanyScenarios
.newFundScenario
.inject(rampUsers(Integer.getInteger("users", 1)) during
(Integer.getInteger("ramp", 1) minutes))
setUp(
generalCompanyTestCases.protocols(httpConf),
)
}
Now the issue is that for one user i want to read data in loop in my newFundScenario but in this case it just picks 1st value from json file.
Something like
foreach(read data from json file){
//Pass Data in run time and execute
.exec(UploadFundDocsInPassfort.upload_fund_s3).exitHereIfFailed
.exec(UploadFundDocsInPassfort.upload_fund_passfort).exitHereIfFailed
}
Any help is much appreciated.
Regards, Vikram Pathania