【发布时间】:2019-06-28 01:39:47
【问题描述】:
我是 gatling 和 scala 的新手。我正在尝试做以下事情:-
test.json:
[
{
"code": "AML",
"data": "aaasdfgghh"
},
{
"code": "ABC",
"data": "aaasdfgghh"
},
{
"code": "SDF",
"data": "aaasdfgghh"
}
]
现在我想在循环中读取这个 json 键/值。目前我正在这样做:
请求正文和馈线:-
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"))
我的场景是:-
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
我的测试模拟是:
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),
)
}
现在的问题是,对于一个用户,我想在我的 newFundScenario 中循环读取数据,但在这种情况下,它只是从 json 文件中选择第一个值。
有点像
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
}
非常感谢任何帮助。
问候, 维克拉姆·帕塔尼亚
【问题讨论】:
标签: scala gatling scala-gatling