randomSwitch and .exec

Hi,

I am using a randomSwitch for traffic weightings.

.randomSwitch(
60d → exec(http(“Desktop”)
.get("${cbbcUrl}")
.exec(addCookie(Cookie(“ckps_d”, “d”)))
.header(“User-Agent”, “Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Firefox/31.0”)
.check(status.is(200))))

I note that we remove the dot notation from exec which works fine. The problem is when I add another .exec to add cookie. Do I need to add addCookie in an exec block?

Many Thanks

Aidy

You’re not adding your exec(addCookie) in the proper place!
You can’t just call exec in the middle of a request definition.

exec(addCookie(Cookie(“ckps_d”, “d”))) // add a cookie to the CookieJar

.exec(http(“Desktop”)
.get("${cbbcUrl}")
.header(“User-Agent”, “Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Firefox/31.0”)

.check(status.is(200)))

Hi Stéphane,

Yes, you are right.

Many Thanks

Aidy

You’re welcome :slight_smile: