How to perform two exec using doIfEqualsOrElse

403 views
Skip to first unread message

Zhu Hui Wang

unread,
Apr 27, 2015, 7:03:31 AM4/27/15
to gat...@googlegroups.com
Hey ,

I am trying to manually add in a cookie value in my load test to simulate logged in users based on if "sec_user_id" has NOT got the value "none" in the file I am feeding into the test. There seems to be two bits I am stuck on:
1. I can't seem to get the second 'exec' statement to work (highlighted in red) when using doIfEqualsOrElse (I have followed the example in http://gatling.io/docs/2.0.0-RC5/general/scenario.html)
2. The test seem to like '.addCookie'

 val scn = scenario("Jaccess log one hour scenario")
      .feed(Jaccess_log)
      .doIfEqualsOrElse("${sec_user_id}", "none") {
      exec(
        http("Search Flow non login")
          .get("${URL}")
          .check(status.is(200))
      )
      } {
        exec(
          http("Search Flow login")
            .get("${URL}")
            .addCookie(Cookie("name", "value"))
        )
      }

Any help would be appreciated.

Thanks

Hui

Guillaume CORRE

unread,
Apr 27, 2015, 9:38:25 AM4/27/15
to gat...@googlegroups.com
Hi,

First, the doc you are referring to is quite old, try this one: http://gatling.io/docs/2.1.5/http/http_helpers.html

Then, what the old doc says is still valid. addCookie isn't a method you call on a http request, it is a method you call on its own :

exec(addCookie(Cookie("name", "value")))

I would also suggest you call it before the actual request.

Cheers!
Guillaume

--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zhu Hui Wang

unread,
Apr 27, 2015, 10:09:56 AM4/27/15
to gat...@googlegroups.com
Thanks for you help Guillaume!

If I call the addCookie menthod before making the http request how could I use it in this scenario which is "if sec_user_id == "none" then get the URL if NOT then simulate a login cookie and get the URL in the http request"

Thanks

Hui

Guillaume CORRE

unread,
Apr 27, 2015, 10:48:36 AM4/27/15
to gat...@googlegroups.com
Ffd

exec(addCookie(Cookie("name", "value")))
val scn = scenario("Jaccess log one hour scenario")
  .feed(Jaccess_log)
  .doIfEqualsOrElse("${sec_user_id}", "none") {
    exec(
      http("Search Flow non login")
        .get("${URL}")
        .check(status.is(200))
      )
    } {exec(addCookie(Cookie("name", "value")))
      exec(
        http("Search Flow login")
          .get("${URL}")
          .addCookie(Cookie("name", "value"))
        )
      }

Cheers,
Guillaume.

Guillaume CORRE

unread,
Apr 27, 2015, 10:52:49 AM4/27/15
to gat...@googlegroups.com
Whoops, wrong shortcut...

Like I said : Before the exec(http.get()), in the second block of the doIfEqualsOrElse, so it looks like this:

val scn = scenario("Jaccess log one hour scenario")
  .feed(Jaccess_log)
  .doIfEqualsOrElse("${sec_user_id}", "none") {
    exec(
      http("Search Flow non login")
        .get("${URL}")
        .check(status.is
(200))
    )
  } {
    exec(addCookie(Cookie("name", "value"))
     .exec(
        http("Search Flow login")
          .get("${URL}")))
  }

Cheers,
Guillaume.

Guillaume CORRE

unread,
Apr 27, 2015, 10:54:27 AM4/27/15
to gat...@googlegroups.com
Plus the missing parentheses at the end of the addCookie line ... :)

Zhu Hui Wang

unread,
Apr 27, 2015, 11:51:31 AM4/27/15
to gat...@googlegroups.com
Thank you so much!! :-)
Reply all
Reply to author
Forward
0 new messages