如何从Gatling中的进纸器访问会话中存储的值
问题描述:
在我的Gatling方案中,会话中为用户存储值。 后来在相同的情况下,Feed被调用并通过自定义进纸器。自定义进纸器需要使用会话中存储的值生成其下一个值。如何从Gatling中的进纸器访问会话中存储的值
val MyScenario = scenario("ScenerioName")
.repeat(10, "repetition") {
exitBlockOnFail {
group("WorkflowGroupName") {
exec(session => {
// SETTING A VALUE INTO THE USER'S SESSION
session.set("sessionVariable", 99) // value that is stored changes for every run of the workflow (99 just for example purposes)
})
// CUSTOM FEEDER THAT GENERATES ITS NEXT VALUE USING THE SESSION VARIABLE 'sessionVariable' STORED ABOVE
.feed(myFeeder)
.group("RequestGroup1") {
exec(httpPost1)
}
}
}
}
val myFeeder = Iterator.continually(Map("jsonFileValue" -> {
// WANT TO RETRIEVE VALUE OF 'sessionVariable' STORED IN THE SESSION
val returnValue = /* logic that generates its value based on value of 'sessionVariable' retrieved */
returnValue
}
))
val httpPost1 = http("Request1")
.post("http://IPAddress/service.svc")
.headers(httpHeaders)
.body(ELFileBody("MyJsonFile.json"))
.check(status.is(200))
val httpHeaders = Map(
"Content-Type" -> "application/json; charset=UTF-8",
"X-Pod" -> ""
)
如何将此存储的会话值传递给馈线或让馈线从会话中检索此值?
答
由于documentation状态:
有时候,你可能要筛选根据 从会议的一些信息注入数据。
Feeder无法实现这一点,因为它只是一个迭代器,所以它不知道 的上下文。
如果您的值与您运行的测试无关,也许一个好方法是在运行测试之前生成csv,然后将此csv提供给您的测试。