So I have a scenario that works perfectly, its defined as follows:
val basicLoginScenario = createScenario(Config.testName, feeder.random,
setSessionParams(PARAM1, Config.param1),
setSessionParams(PARAM2, Config.param2),
setSessionParams(PARAM3, Config.param3),
setSessionParams(PARAM4, Config.param4),
exec(RestApi.userLogin))
exec(RestApi.transaction1))
exec(RestApi.transaction2)))
But when I surround it with exitBlockOnFail, I am getting the following error and it seems to happen before any HTTP request is sent or any request/response JSON is being parsed.
[GatlingSystem-akka.actor.default-dispatcher-4] ERROR io.gatling.http.action.HttpRequestAction - 'httpRequest-5' failed to execute: No attribute named 'cookie' is defined
This is the code with exitBlockOnFail:
val basicLoginScenario = createScenario(Config.testName, feeder.random,
exitBlockOnFail{
setSessionParams(PARAM1, Config.param1)
setSessionParams(PARAM2, Config.param2)
setSessionParams(PARAM3, Config.param3)
setSessionParams(PARAM4, Config.param4)
exec(RestApi.userLogin))
exec(RestApi.transaction1))
exec(RestApi.transaction2))
})
Note that the "cookie" parameter is being fetched from the userLogin transaction and is not used anywhere before it is fetched in this scenario, obviously not in setSessionParam which is:
def setSessionParams(key: String, value: Any) = {
exec(_.set(key, value))
}
Here is the userLogin transaction:
val userLogin = {
exec(http("Login")
.post("/login")
.body(ElFileBody("json/Login.json")).asJson
.check(jsonPath("$.result.cookie").saveAs("cookie")))
}
My feeder doesn't have a "cookie" parameter in it and the Login.json doesn't have a "cookie" parameter assigned in it, it only returns it. As I said at the beginning, the scenario works perfectly - the issue only occurs when i surround my transactions with exitBlockOnFail. Any idea what might cause it?
Your initial version works because 'exec' can take a varargs of execs whereas 'exitBlockOnFail' takes a chain. So when you supply several execs to 'exitBlockOnFail', only the last action is being executed.
so you can either wrap all the statements in an 'exec'
exitBlockOnFail{
exec(
setSessionParams(PARAM1, Config.param1),
...
exec(RestApi.transaction2)
)
}
or chain them
exitBlockOnFail{
setSessionParams(PARAM1, Config.param1)
.setSessionParams(PARAM1, Config.param1)
.setSessionParams(PARAM2, Config.param2)
.setSessionParams(PARAM3, Config.param3)
.setSessionParams(PARAM4, Config.param4)
.exec(RestApi.userLogin)
.exec(RestApi.transaction1)
.exec(RestApi.transaction2)
}