# Feeders

**URL:** <https://community.gatling.io/t/feeders/612>\
**Category:** Gatling (Open-Source)\
**Created:** [October 9, 2013, 3:07pm UTC](https://community.gatling.io/t/feeders/612 "2013-10-09T15:07:20Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prescillia\_Duvauchel](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Prescillia\_Duvauchel](https://community.gatling.io/u/Prescillia_Duvauchel)\
**Post date:** [October 9, 2013, 3:07pm UTC](https://community.gatling.io/t/feeders/612/1 "2013-10-09T15:07:20Z")

</div>

Hi All,

I would like to use all datas in my csv file and I did not found how to do it.

In my example, I have products.csv :

skuid,parentid  
540,148  
656,32  
332,105

And a get query which doing an add action:

.repeat(3) {

feed(products)  
.exec(  
http(“add 3 random products in anonymous cart”)  
.get(urlEcomm + “cart.html”)  
.queryParam(“action”, “add”)  
.queryParam(“skuId”, “${skuid}”)  
.queryParam(“quantity”, “1”)  
.queryParam(“parentId”, “${parentid}”)  
.queryParam(“modal”, “true”)  
.queryParam("\_", “1379948801309”)  
.check(status.is(200)))  
.pause(2000 milliseconds)

}

So i would like to add the 3 products.

Ho can i do it ?

Thank youu !!

---

<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:** [October 9, 2013, 3:18pm UTC](https://community.gatling.io/t/feeders/612/2 "2013-10-09T15:18:30Z")

</div>

There’s plenty of examples for this in this mailing list archive.  
Please dig.

---

<div class="post-metadata">

**Author:** ![Prescillia\_Duvauchel](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Prescillia\_Duvauchel](https://community.gatling.io/u/Prescillia_Duvauchel)\
**Post date:** [October 10, 2013, 7:41am UTC](https://community.gatling.io/t/feeders/612/3 "2013-10-10T07:41:41Z")

</div>

Hi,

I found loop and circular solutions but it doesn’t work.

// doesn’t find .loop

.loop (  
feed(products)  
.exec(  
http(“add 3 random products in anonymous cart”)  
.get(urlEcomm + “cart.html”)  
.queryParam(“action”, “add”)  
.queryParam(“skuId”, “${skuid}”)  
.queryParam(“quantity”, “1”)  
.queryParam(“parentId”, “${parentid}”)  
.queryParam(“modal”, “true”)  
.queryParam("\_", “1379948801309”)  
.check(status.is(200)))  
.pause(2000 milliseconds)  
)

.repeat(3) {  
feed(products.circular)  
.exec(  
http(“add 3 random products in anonymous cart”)  
.get(urlEcomm + “cart.html”)  
.queryParam(“action”, “add”)  
.queryParam(“skuId”, “${skuid}”)  
.queryParam(“quantity”, “1”)  
.queryParam(“parentId”, “${parentid}”)  
.queryParam(“modal”, “true”)  
.queryParam("\_", “1379948801309”)  
.check(status.is(200)))  
.pause(2000 milliseconds)  
}

This solution gives:

1st user: cart="a=540:3  
2nd user: cart="a=332:1,656:2  
3rd user: cart="a=656:1,332:2

The 3 products are not added…

Thanks

---

<div class="post-metadata">

**Author:** ![Prescillia\_Duvauchel](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Prescillia\_Duvauchel](https://community.gatling.io/u/Prescillia_Duvauchel)\
**Post date:** [October 10, 2013, 3:12pm UTC](https://community.gatling.io/t/feeders/612/4 "2013-10-10T15:12:14Z")

</div>

Hi,

I can’t use .loop.  
Is the problem the Gatling version ?  
I am working with Gatling 1.5.2.

Then i tried foreach function, doesn’t work too… ☹

.foreach("${skuid}", “product”) {  
exec(  
http(“add 3 random products in client cart”)  
.get(urlEcomm + “cart.html”)  
.queryParam(“action”, “add”)  
.queryParam(“skuId”, “${skuid}”)  
.queryParam(“quantity”, “1”)  
.queryParam(“parentId”, “${parentid}”)  
.queryParam(“modal”, “true”)  
.queryParam("\_", “137994812548”)  
.check(status.is(200)))  
.pause(2000 milliseconds)  
}

Can you clear me please ?

Thank you

---

<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:** [October 10, 2013, 3:33pm UTC](https://community.gatling.io/t/feeders/612/5 "2013-10-10T15:33:32Z")

</div>

Hi,

.repeat(3) {  
feed(products.circular)

.exec(  
http(“add 3 random products in anonymous cart”)  
.get(urlEcomm + “cart.html”)  
.queryParam(“action”, “add”)  
.queryParam(“skuId”, “${skuid}”)  
.queryParam(“quantity”, “1”)  
.queryParam(“parentId”, “${parentid}”)  
.queryParam(“modal”, “true”)  
.queryParam("\_", “1379948801309”)  
.check([status.is](http://status.is/)(200)))  
.pause(2000 milliseconds)  
}

is more or less the right way. Just maybe that Feeders are **_shared_** amongst users. So if you have more that 1 user, you might end up having users selecting several times the same product.  
Is that what you want?

---

<div class="post-metadata">

**Author:** ![Prescillia\_Duvauchel](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Prescillia\_Duvauchel](https://community.gatling.io/u/Prescillia_Duvauchel)\
**Post date:** [October 10, 2013, 3:40pm UTC](https://community.gatling.io/t/feeders/612/6 "2013-10-10T15:40:19Z")

</div>

Thanks for your quik reply 🙂

Indeed, my file is shared amongst users…  
When i execute it with 1 user, it works good, not with several one.  
I would like to add the 3 products to each user.

Is it possible ?  
How can I do it ?

Thanks a lot !!

---

<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:** [October 10, 2013, 3:55pm UTC](https://community.gatling.io/t/feeders/612/7 "2013-10-10T15:55:55Z")

</div>

repeat(3, “i”) {  
exec(session =\>  
val i = session.getTypedAttributeInt  
val record = product(i)  
session.setAttributes(record)  
)

.exec(  
http(“add 3 random products in anonymous cart”)  
.get(urlEcomm + “cart.html”)  
.queryParam(“action”, “add”)  
.queryParam(“skuId”, “${skuid}”)  
.queryParam(“quantity”, “1”)  
.queryParam(“parentId”, “${parentid}”)  
.queryParam(“modal”, “true”)  
.queryParam("\_", “1379948801309”)  
.check([status.is](http://status.is/)(200)))  
.pause(2000 milliseconds)

}

---

<div class="post-metadata">

**Author:** ![Prescillia\_Duvauchel](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Prescillia\_Duvauchel](https://community.gatling.io/u/Prescillia_Duvauchel)\
**Post date:** [October 10, 2013, 4:03pm UTC](https://community.gatling.io/t/feeders/612/8 "2013-10-10T16:03:32Z")

</div>

Thanks !!

But there is an error:

[ERROR] [10/10/2013 18:00:19.468] [GatlingSystem-akka.actor.default-dispatcher-6] [akka://GatlingSystem/user/$L] java.lang.Integer cannot be cast to scala.runtime.Nothing$  
java.lang.ClassCastException: java.lang.Integer cannot be cast to scala.runtime.Nothing$  
at com.intuiko.training.gatling.test.ClientCartScenario$$anonfun$2.apply(ClientCartScenario.scala:55)  
at com.intuiko.training.gatling.test.ClientCartScenario$$anonfun$2.apply(ClientCartScenario.scala:54)  
at com.excilys.ebi.gatling.core.action.SimpleAction.execute(SimpleAction.scala:37)  
at com.excilys.ebi.gatling.core.action.Action$$anonfun$receive$1.apply(Action.scala:31)  
at com.excilys.ebi.gatling.core.action.Action$$anonfun$receive$1.apply(Action.scala:30)  
at akka.actor.Actor$class.apply(Actor.scala:318)  
at com.excilys.ebi.gatling.core.action.SimpleAction.apply(SimpleAction.scala:29)  
at akka.actor.ActorCell.invoke(ActorCell.scala:626)  
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197)  
at akka.dispatch.Mailbox.run(Mailbox.scala:179)  
at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:516)  
at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259)  
at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975)  
at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1479)  
at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)

---

<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:** [October 10, 2013, 4:10pm UTC](https://community.gatling.io/t/feeders/612/9 "2013-10-10T16:10:45Z")

</div>

Could you tell me what line 55 is, please? Crystal ball is broken.

at com.intuiko.training.gatling.test.ClientCartScenario$$anonfun$2.apply(ClientCartScenario.scala:55)

---

<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:** [October 10, 2013, 4:11pm UTC](https://community.gatling.io/t/feeders/612/10 "2013-10-10T16:11:47Z")

</div>

And share you scenario (gist, pastebin)

---

<div class="post-metadata">

**Author:** ![Prescillia\_Duvauchel](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Prescillia\_Duvauchel](https://community.gatling.io/u/Prescillia_Duvauchel)\
**Post date:** [October 11, 2013, 7:14am UTC](https://community.gatling.io/t/feeders/612/11 "2013-10-11T07:14:31Z")

</div>

Hi Stéphane,

Sorry it is now line 46:  
val i = session.getTypedAttributeInt

Here my scenario: [https://gist.github.com/anonymous/6930747](https://gist.github.com/anonymous/6930747)

Thanks

---

<div class="post-metadata">

**Author:** ![Prescillia\_Duvauchel](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Prescillia\_Duvauchel](https://community.gatling.io/u/Prescillia_Duvauchel)\
**Post date:** [October 11, 2013, 12:47pm UTC](https://community.gatling.io/t/feeders/612/12 "2013-10-11T12:47:06Z")

</div>

get it !! Thanks so much !!

I have another question. In my scenario [https://gist.github.com/anonymous/6930747](https://gist.github.com/anonymous/6930747), i would like for each user (for example 5 users ClientCartScenario.scn.users(5)), a random client saved in the csv file users.csv:

login,password  
[prescillia.duvauchelle@intuiko.com](mailto:prescillia.duvauchelle@intuiko.com),123456  
[john.doe@intuiko.com](mailto:john.doe@intuiko.com),123456  
[fassol.remy@intuiko.com](mailto:fassol.remy@intuiko.com),123456

So I did first before the scenario:

val user = csv(“users.csv”).random  
val login = user.next()(“login”)  
val password = user.next()(“password”)

But, obviously, the same client is manipulated for the 5 users. So i tried this solution:

.exec(session =\> {

val user = csv(“users.csv”).random  
val login = user.next()(“login”)  
val password = user.next()(“password”)

session.setAttribute(“login”, login)  
session.setAttribute(“password”, password)

})

And i use the login and password like this:

.exec(  
http(“1st connexion”)  
.post(urlEcomm + “secure/login.html”)  
.param(“login”, “${login}”)  
.param(“password”, “${password}”)  
.check(status.is(200)))  
.pause(2000 milliseconds)

It’s works but the cart is not conserved, as it was just save in the current session.

Why this result ?  
Is it the best way to do that ?

Thank you !!

---

<div class="post-metadata">

**Author:** ![Prescillia\_Duvauchel](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Prescillia\_Duvauchel](https://community.gatling.io/u/Prescillia_Duvauchel)\
**Post date:** [October 11, 2013, 3:39pm UTC](https://community.gatling.io/t/feeders/612/13 "2013-10-11T15:39:35Z")

</div>

Ok I understand… It doesn’t work because of the current session…

Is it possible to feed all queries ?  
Like this :

val scn = {  
scenario(“scenario name”)

.feed(csv(“users.csv”).random) {

.exec(  
http(“1st connexion”)  
.post(urlEcomm + “/StarterEcommerce/secure/login.html”)  
.param(“login”, “${login}”)  
.param(“password”, “${mdp}”)  
.check(status.is(200)))  
.pause(2000 milliseconds)

…

.exec(  
http(“2nd connexion”)  
.post(urlEcomm + “/StarterEcommerce/secure/login.html”)  
.param(“login”, “${login}”)  
.param(“password”, “${mdp}”)  
.check(status.is(200)))  
.pause(2000 milliseconds)

…  
}  
}

---

<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:** [October 11, 2013, 8:06pm UTC](https://community.gatling.io/t/feeders/612/14 "2013-10-11T20:06:06Z")

</div>

3 last emails:

1. the ClassCastException happens because you wrote getTypedAttribute(“i”) instead of getTypedAttributeInt  
2 and 3) Now, this is a proper use case for regular feeders:

val scn = {  
scenario(“scenario name”)  
.feed(csv(“users.csv”).random) // workflow step, when a given user reaches here, it pulls a record out of the feeder

.exec(  
http(“1st connexion”)

.post(urlEcomm + “/StarterEcommerce/secure/login.html”)  
.param(“login”, “${login}”)  
.param(“password”, “${mdp}”)  
.check([status.is](http://status.is/)(200)))  
.pause(2000 milliseconds)

…

.exec(  
http(“2nd connexion”)  
.post(urlEcomm + “/StarterEcommerce/secure/login.html”)  
.param(“login”, “${login}”)  
.param(“password”, “${mdp}”)  
.check([status.is](http://status.is/)(200)))  
.pause(2000 milliseconds)

…  
}

Cheers,

Stéphane

---

<div class="post-metadata">

**Author:** ![Prescillia\_Duvauchel](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Prescillia\_Duvauchel](https://community.gatling.io/u/Prescillia_Duvauchel)\
**Post date:** [October 14, 2013, 7:49am UTC](https://community.gatling.io/t/feeders/612/15 "2013-10-14T07:49:17Z")

</div>

Hi Stéphane,

It is really strange because it doesn’t work when I execute 2 connection queries following like this: [https://gist.github.com/anonymous/6972198](https://gist.github.com/anonymous/6972198)  
With this solution, the result is:

1st connection = cart="a=540:2,656:3,332:11,nb=16 //It works  
2nd connection & add random product = JSESSIONID=D216D7C29A29162066DDC95E52F66C72 //doesn’t work

Mobile connection = cart="a=540:2,656:3,332:12,nb=17 //It works

But when I execute the first connection, then the mobile connection, and finally the second connection, like this: [https://gist.github.com/anonymous/6972223](https://gist.github.com/anonymous/6972223), it works good.  
The result is:

1st connection = cart="a=540:2,656:3,332:11,nb=16

Mobile connection = cart="a=540:2,656:3,332:11,nb=16

2nd connection & add random product = cart="a=540:2,656:3,332:12,nb=17

What is the problem ?

Thanks

Prescillia

---

<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:** [October 14, 2013, 9:15am UTC](https://community.gatling.io/t/feeders/612/16 "2013-10-14T09:15:59Z")

</div>

Hi,

I won’t have time to dig this for you, but basically, I’d say your problem is with this kind of code:  
.check(header(“Set-Cookie”).saveAs(“cart”))

Here, you’re checking for the FIRST Set-Cookie header:  
[https://github.com/excilys/gatling/wiki/Checks#wiki-extracting](https://github.com/excilys/gatling/wiki/Checks#wiki-extracting)

Your problem is that you assume that your cart header is always the first one. Obviously, the JSESSIONID might come first.  
In Gatling 2, there’s many ways to filter/extract to header of your choice. Things are more limited in Gatling 1. I advice you go with headerRegex: [https://github.com/excilys/gatling/wiki/Checks#wiki-header-regex](https://github.com/excilys/gatling/wiki/Checks#wiki-header-regex)

Generally speaking, you have many complex use cases and you’d better upgrade to Gatling 2.

Stéphane
