# Getting feeder values from a session function

**URL:** <https://community.gatling.io/t/getting-feeder-values-from-a-session-function/1177>\
**Category:** Gatling (Open-Source)\
**Created:** [July 15, 2014, 11:39pm UTC](https://community.gatling.io/t/getting-feeder-values-from-a-session-function/1177 "2014-07-15T23:39:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_Lichtenberg](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@Tom\_Lichtenberg](https://community.gatling.io/u/Tom_Lichtenberg)\
**Post date:** [July 15, 2014, 11:39pm UTC](https://community.gatling.io/t/getting-feeder-values-from-a-session-function/1177/1 "2014-07-15T23:39:33Z")

</div>

Hi -  
Can I get the current feeder values from a session function like the one below (getData)? (I’m using the 2.x snapshot from July 1, 2014). The getData function is for putting together a JSON post body including values from the csv file defined by the feeder and used by potentially different paths.

val getData = exec((session) =\> {  
count = count + 1  
the\_username = session.getTypedAttribute(“username”) // wanting to get ‘username’ from the csv feeder here, but how? this does not compile (getTypedAttribute is not a method of Session and seems to be deprecated anyway)  
the\_password = session.getTypedAttribute(“password”) // wanting to get ‘password’ from the csv feeder here, but how?  
val data: String = “”"{ “user”: “”" + the\_username + “”",“password”:""" + the\_password + “”"}"""  
session.set(“message”, data)  
}  
)

val scn = scenario(“Feeder Test”)  
.feed(userCredentials)  
.repeat(1) {  
exec(getData)  
.doIfOrElse((session:Session) =\> count % 10 == 0) {  
chain1  
} {  
randomSwitch (  
percentage1 → chain2,  
percentage2 → chain3  
)  
}  
.pause(1000 milliseconds)  
}

Thanks in advance  
Tom

---

<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:** [July 16, 2014, 5:28am UTC](https://community.gatling.io/t/getting-feeder-values-from-a-session-function/1177/2 "2014-07-16T05:28:33Z")

</div>

Hi,

Did you check out this page? [https://github.com/excilys/gatling/wiki/Gatling%202](https://github.com/excilys/gatling/wiki/Gatling%202)

If the data comes from a feeder, it’s safe to assume it’s indeed here (not depending on a check that might have failed) and use “as”:  
session(“username”).as[String]

Then, you probably don’t define the variables properly (count, the\_username, the\_password).  
If I get it properly:

- the\_username and the\_password are only used inside the function, so they should be defined as local val.

- count is a global counter, so it should be an AtomicInteger or you’ll experience race conditions/visibility issues as the function will be executed by multiple concurrent threads.

Cheers,

Stéphane

---

<div class="post-metadata">

**Author:** ![Tom\_Lichtenberg](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@Tom\_Lichtenberg](https://community.gatling.io/u/Tom_Lichtenberg)\
**Post date:** [July 16, 2014, 4:34pm UTC](https://community.gatling.io/t/getting-feeder-values-from-a-session-function/1177/3 "2014-07-16T16:34:04Z")

</div>

Thanks, Stephane. I see that in the Wiki now.
