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

**URL:** <https://community.gatling.io/t/is-it-possible-to-cause-a-scenario-to-fail-when-session-attribute-is-missing-wrong-value/3105>\
**Category:** Gatling (Open-Source)\
**Created:** [June 27, 2016, 8:46am UTC](https://community.gatling.io/t/is-it-possible-to-cause-a-scenario-to-fail-when-session-attribute-is-missing-wrong-value/3105 "2016-06-27T08:46:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Craig\_Jones](https://avatars.discourse-cdn.com/v4/letter/c/a88e57/32.png) [@Craig\_Jones](https://community.gatling.io/u/Craig_Jones)\
**Post date:** [June 27, 2016, 8:46am UTC](https://community.gatling.io/t/is-it-possible-to-cause-a-scenario-to-fail-when-session-attribute-is-missing-wrong-value/3105/1 "2016-06-27T08:46:04Z")

</div>

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") cookie.map(session.set("cookieName", _)) }).getOrElse(session) newSession })`

Any help would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Craig\_Jones](https://avatars.discourse-cdn.com/v4/letter/c/a88e57/32.png) [@Craig\_Jones](https://community.gatling.io/u/Craig_Jones)\
**Post date:** [June 27, 2016, 2:14pm UTC](https://community.gatling.io/t/is-it-possible-to-cause-a-scenario-to-fail-when-session-attribute-is-missing-wrong-value/3105/2 "2016-06-27T14:14:07Z")

</div>

(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! 🙂

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [July 8, 2016, 6:26am UTC](https://community.gatling.io/t/is-it-possible-to-cause-a-scenario-to-fail-when-session-attribute-is-missing-wrong-value/3105/3 "2016-07-08T06:26:45Z")

</div>

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