# Stop simulation for 1 user if check fails

**URL:** <https://community.gatling.io/t/stop-simulation-for-1-user-if-check-fails/1249>\
**Category:** Gatling (Open-Source)\
**Created:** [August 7, 2014, 7:10am UTC](https://community.gatling.io/t/stop-simulation-for-1-user-if-check-fails/1249 "2014-08-07T07:10:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrei\_Proskurin](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Andrei\_Proskurin](https://community.gatling.io/u/Andrei_Proskurin)\
**Post date:** [August 7, 2014, 7:10am UTC](https://community.gatling.io/t/stop-simulation-for-1-user-if-check-fails/1249/1 "2014-08-07T07:10:10Z")

</div>

Hi,  
At the moment I have the following check in my simulation:

check(regex("\<a wicket:id=“edit” href="._(${pattern}declarations-${countEdit}-edit)"\>Paranda._").saveAs("someUrl))

What I want is to insert a condition that if this check fails, then this user (for whom the check failed) stops simulation. And others should continue. The thing is that the check fails for some users (it should fail) but for others it’s ok.

---

<div class="post-metadata">

**Author:** ![Andrei\_Proskurin](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Andrei\_Proskurin](https://community.gatling.io/u/Andrei_Proskurin)\
**Post date:** [August 7, 2014, 7:13am UTC](https://community.gatling.io/t/stop-simulation-for-1-user-if-check-fails/1249/2 "2014-08-07T07:13:47Z")

</div>

In gatling 2.0.0 rc1 cheatsheet I found command **exitHereIfFailed** , but how do I use it?

---

<div class="post-metadata">

**Author:** ![Pierre\_DAL-PRA](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@Pierre\_DAL-PRA](https://community.gatling.io/u/Pierre_DAL-PRA)\
**Post date:** [August 7, 2014, 7:23am UTC](https://community.gatling.io/t/stop-simulation-for-1-user-if-check-fails/1249/3 "2014-08-07T07:23:17Z")

</div>

Hi Andrei,

You can achieve this behaviour by checking if the session contains the supposedly saved attribute, and marking the session as failed if it doesn’t.  
Then you call exitHereIfFailed, which will skip the rest of the scenario if the session was marked as failed.

.exec(session =\> if(session.contains(“someUrl”)) session else session.markAsFailed)  
.exitHereIfFailed

Cheers,

Pierre

---

<div class="post-metadata">

**Author:** ![Andrei\_Proskurin](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Andrei\_Proskurin](https://community.gatling.io/u/Andrei_Proskurin)\
**Post date:** [August 7, 2014, 7:33am UTC](https://community.gatling.io/t/stop-simulation-for-1-user-if-check-fails/1249/4 "2014-08-07T07:33:04Z")

</div>

Works great, with the one exception. It generates the error, that the regex was not found. So in the .html report there is a bunch of failed requests. Is there any way to avoid it? If not, I’ll just stick to this solution. Thanks again!

---

<div class="post-metadata">

**Author:** ![Pierre\_DAL-PRA](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@Pierre\_DAL-PRA](https://community.gatling.io/u/Pierre_DAL-PRA)\
**Post date:** [August 7, 2014, 10:02am UTC](https://community.gatling.io/t/stop-simulation-for-1-user-if-check-fails/1249/5 "2014-08-07T10:02:04Z")

</div>

You can use ‘dontValidate’ when defining your check to tell Gatling not to consider the request failed if the check didn’t succeed :

check(regex("\<a wicket:id=“edit” href="._(${pattern}declarations-${countEdit}-edit)"\>Paranda._").dontValidate.saveAs("someUrl))

---

<div class="post-metadata">

**Author:** ![Andrei\_Proskurin](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Andrei\_Proskurin](https://community.gatling.io/u/Andrei_Proskurin)\
**Post date:** [August 7, 2014, 11:12am UTC](https://community.gatling.io/t/stop-simulation-for-1-user-if-check-fails/1249/6 "2014-08-07T11:12:10Z")

</div>

Works flawlessly! Thank you again.

---

<div class="post-metadata">

**Author:** ![Pierre\_DAL-PRA](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@Pierre\_DAL-PRA](https://community.gatling.io/u/Pierre_DAL-PRA)\
**Post date:** [August 7, 2014, 4:02pm UTC](https://community.gatling.io/t/stop-simulation-for-1-user-if-check-fails/1249/7 "2014-08-07T16:02:35Z")

</div>

You’re welcome !

Have fun with Gatling 🙂

Cheers,

Pierre
