Is it possible to cause a scenario to fail when session attribute is missing/wrong value?

Hi there,

I am wondering if its possible to cause a scenario to fail if a session attribute is missing. This sounds relatively simple on the surface so let me add a simple scenario:

What I want to do is make a POST to / with some data, and verify that a cookie is being set and I see a 200.

val postUserSignin = exec(http("POST Signin") .post("/") .formParam("username", "${username}") .check(status is 200) .exec(session => { // get cookie value from cookiejar on session - omitted for brevity session.set("cookieName", _) session }) .check(// check cookie value is set);

Unfortunately the POST includes a 301 redirect so the cookie isn’t in the standard set-cookie header on the response. This means I need to get it from the session first.

Obviously the check above cannot be used here, I just added it for illustration. I have seen the session.markAsFailed and exitHereIfFailed but neither seem to work when added to the exec, the scenario is marked as passed regardless, even if I always set session.markAsFailed true every time.

In short, im stuck.

Fuller example including my cookie parsing, perhaps markAsFailed is the answer and i’m just missing something obvious:

val postUserSignin = exec(http("POST Signin") .post("/") .formParam("username", "${username}") // other form params omitted for brevity .check(status is 200) .exec(session => { import io.gatling.http.cookie._ import com.ning.http.client.uri.Uri._ val newSession = (session("gatling.http.cookies").asOption[CookieJar].flatMap { cookieJar => val cookie = cookieJar.get(com.ning.http.client.uri.Uri.create("<THE URL>")).find(_.getName == "cookieName")"cookieName", _)) }).getOrElse(session) newSession })

Any help would be greatly appreciated.

(This is gatling 2.11 btw)

Still no closer on this one, however have realised that markAsFailed is almost certainly not the answer as I now don’t believe its meant to KO the user/thread in that scenario.

Alternatively if anyone knows how to KO a scenario manually that would also be very useful! :slight_smile:

What do you mean by “cause a scenario to fail”?
Are you looking for “exitBlockOnFail” and “exitHereIfFailed”?