share connection between several scenarios

Hi everybody,

I am working with Gatling 2 to test a website’s electronic cart.
You can do your shopping in live…
We did a persistant cart, for example: an anonymous client is visiting the website, then he adds some articles. He closes the browser and when he re-open it, he finds the same cart saved in the session…

My job is to test this session. I would like to use the SAME user to recover the session saved.

Here that I would like :

val httpConf = httpConfig.baseURL(“”)


val scn1 = {
scenario(“consult random products, update quantity in cart”)
.repeat(5) {
http(“view a product”)
.queryParam(“langId”, “1”)
.queryParam(“ceId”, “${parentid}”)
.pause(200 milliseconds)

http(“add product”)
.queryParam(“action”, “add”)
.queryParam(“skuId”, “540”)
.queryParam(“quantity”, “1”)
.queryParam(“parentId”, “148”)
.queryParam(“modal”, “true”)
.queryParam("_", “1379948801309”)
.pause(2000 milliseconds)

http(“update quantity”)
.queryParam(“action”, “updateQuantity”)
.queryParam(“skuId”, “${skuid}”)
.queryParam(“quantity”, “2”)
.pause(100 milliseconds)

http(“get cart”)

.exec(session => {

import com.excilys.ebi.gatling.http.cookie._

val cart = session.getAttribute(“cart”)
println("1st connection. Cart = " + cart.toString); session

val scn2 = {
scenario(“second connection”)
http(“get cart”)

.exec(session => {
import com.excilys.ebi.gatling.http.cookie._

val ck = session.getAttribute(“cart”)
println("2nd connection. Cart = "+ck.toString); session

Just, i would like to simulate a closing of the browser.

I tried this shareConnections but it doesn’t work…

Please help :frowning:

Thanks !

ps: sorry for my english, i am french :slight_smile:

Sorry I am working with Gatling 1.5.2 :slight_smile:


(always funny when two French people talk together in English)

We don’t support this use case out of the box, (IMHO, more of a functional test than a stress test).
We could, though, but only for Gatling 2.

Let me explain.

Cookies fall into 2 categories:

  • session cookies that get flushed once the browser is closed
  • persistence cookies that get stored on the computer file system until they explicitly expire

Your persistent cart mechanism is implemented on top of the latter.

Implementing browser closing means removing session cookies from Gatling’s user session.

Then, could you upgrade to 1.5.3-SNAPSHOT?

Cookie code in 1.5.2 is not an open API and things are much much easier now.

Here’s the code you need (honestly haven’t tried it):

def closeBrowser(session: Session) = {
import com.excilys.ebi.gatling.http.cookie.CookieHandling._
import com.excilys.ebi.gatling.http.cookie.CookieJar

val cookieJar = session.getTypedAttributeCookieJar
val cookieJarWithoutSessionCookies = CookieJar( != -1)))

session.setAttribute(COOKIES_CONTEXT_KEY, cookieJarWithoutSessionCookies)

then, in your scenario:




Hi Stéphane,

Thank you to reply so fast :slight_smile:

Hum, if I upgrate to 1.5.3, i have to change all my classes…
And i took many time to do this project…

There is no other solution ? really ?
It’s embarrassing… :S

Thanks a lot ! :slight_smile:

For the record: the compilation errors were just a matter of forcing re-compilation.