# How to validate an attribute is defined in Gatling 2?

**URL:** <https://community.gatling.io/t/how-to-validate-an-attribute-is-defined-in-gatling-2/783>\
**Category:** Gatling (Open-Source)\
**Created:** [January 22, 2014, 12:46am UTC](https://community.gatling.io/t/how-to-validate-an-attribute-is-defined-in-gatling-2/783 "2014-01-22T00:46:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kan\_Wu](https://avatars.discourse-cdn.com/v4/letter/k/85e7bf/32.png) [@Kan\_Wu](https://community.gatling.io/u/Kan_Wu)\
**Post date:** [January 22, 2014, 12:46am UTC](https://community.gatling.io/t/how-to-validate-an-attribute-is-defined-in-gatling-2/783/1 "2014-01-22T00:46:43Z")

</div>

in 1.5.3 I could use isAttributeDefined(attributeKey: String) defined at here: [https://github.com/excilys/gatling/wiki/Session#wiki-members](https://github.com/excilys/gatling/wiki/Session#wiki-members)

according to Gatling 2 wiki: [https://github.com/excilys/gatling/wiki/Gatling-2#wiki-session](https://github.com/excilys/gatling/wiki/Gatling-2#wiki-session), this API is not available any more. I basically want to use that in the doIf condition.

i tried

doIf(session =\> session(“parentCardId”).validate[String]) {  
exec(

error message said:

type mismatch;  
found : io.gatling.core.validation.Validation[String]  
required: io.gatling.core.validation.Validation[Boolean]  
16:44:35.309 [ERROR] i.g.a.ZincCompiler$ - .doIf(session =\> session(“userCardId”).validate[String]) {  
16:44:35.309 [ERROR] i.g.a.ZincCompiler$ - ^

but if i replace String with Boolean, error said

value validate is not a member of String  
16:32:24.886 [ERROR] i.g.a.ZincCompiler$ - doIf(session =\> session(“parentCardId”.validate[Boolean]))

Any ideas?

---

<div class="post-metadata">

**Author:** ![Kan\_Wu](https://avatars.discourse-cdn.com/v4/letter/k/85e7bf/32.png) [@Kan\_Wu](https://community.gatling.io/u/Kan_Wu)\
**Post date:** [January 22, 2014, 1:11am UTC](https://community.gatling.io/t/how-to-validate-an-attribute-is-defined-in-gatling-2/783/2 "2014-01-22T01:11:54Z")

</div>

There was a typo in the second try but i fixed that still got this error:  
17:09:24.760 [ERROR] i.g.c.action.If - Can’t cast value 60016 of type class java.lang.String into boolean

finally I use this one and it works:

doIf(session =\> session(“parentCardId”).validate[String].map(\_ != null)) {  
exec(

isnt it using null a bad idea in scala? any other simple way of doing this?

在 2014年1月21日星期二UTC-8下午4时46分43秒，Kan Wu写道：

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [January 22, 2014, 1:31am UTC](https://community.gatling.io/t/how-to-validate-an-attribute-is-defined-in-gatling-2/783/3 "2014-01-22T01:31:36Z")

</div>

If you just want to check that “parentCardId” exists in the session, why not just:  
doIf(session =\> session.contains(“parentCardId”))

or shorter:  
doIf(\_.contains(“parentCardId”))

---

<div class="post-metadata">

**Author:** ![Kan\_Wu](https://avatars.discourse-cdn.com/v4/letter/k/85e7bf/32.png) [@Kan\_Wu](https://community.gatling.io/u/Kan_Wu)\
**Post date:** [January 22, 2014, 1:49am UTC](https://community.gatling.io/t/how-to-validate-an-attribute-is-defined-in-gatling-2/783/4 "2014-01-22T01:49:24Z")

</div>

your way works perfect! thanks!

do you know any where we can find a full list of APIs that session or other objects?

在 2014年1月21日星期二UTC-8下午5时31分36秒，Stéphane Landelle写道：

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [January 22, 2014, 1:51am UTC](https://community.gatling.io/t/how-to-validate-an-attribute-is-defined-in-gatling-2/783/5 "2014-01-22T01:51:07Z")

</div>

For now, you’ll have to browse the code: [https://github.com/excilys/gatling/blob/master/gatling-core/src/main/scala/io/gatling/core/session/Session.scala#L71-L76](https://github.com/excilys/gatling/blob/master/gatling-core/src/main/scala/io/gatling/core/session/Session.scala#L71-L76)  
We’ll document the whole thing in the next weeks.
