How to perform two exec using doIfEqualsOrElse

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

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

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

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](http://status.is)(200))
      )
    } {exec(addCookie(Cookie("name", "value")))
      exec(
        http("Search Flow login")
          .get("${URL}")
          .addCookie(Cookie("name", "value"))
        )
      }

Cheers,
Guillaume.

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](http://status.is)(200))
    )
  } {
    exec(addCookie(Cookie("name", "value"))
     .exec(
        http("Search Flow login")
          .get("${URL}")))
  }

Plus the missing parentheses at the end of the addCookie line … :slight_smile:

Thank you so much!! :slight_smile: