Feeders

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

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

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

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… :frowning:

.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

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(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?

Thanks for your quik reply :slight_smile:

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

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(200)))
.pause(2000 milliseconds)

}

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)

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)

And share you scenario (gist, pastebin)

Hi Stéphane,

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

Here my scenario: https://gist.github.com/anonymous/6930747

Thanks

get it !! Thanks so much !!

I have another question. In my scenario 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,123456
john.doe@intuiko.com,123456
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 !!

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)


}
}

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(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)


}

Cheers,

Stéphane

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
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, 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

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

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

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

Stéphane