You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Anders Eurenius <an...@snowmen.se> on 2009/05/18 10:16:52 UTC

Script access to cookies.

Hi

I have a bit of a problem: the site I'm trying to test uses js to frob a
cookie to communicate state, so I'd really like to be able to do that in
my test as well. Setting a cookie manager cookie to a script fragment
doesn't seem to do it, particularly since I don't want to magically have
the cookie before the server sets it. In short:

...
jmeter: req /able  (no cookie.)
server: ok,        cookie: fnord=1234deadbeef
...magic goes here...
jmeter: req /baker cookie: fnord=1234deadbeef,{"json":"wierdness"}
server: ok...
...

Using a BSF preprocessor to clobber the variable-by-that-name doesn't
seem to work. (I'm guessing it just creates a new variable that shadows
the cookie.)

I could start hacking in Java, but I'd prefer to avoid it.

Thank you.

Anders Eurenius

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: Script access to cookies.

Posted by sebb <se...@gmail.com>.
On 18/05/2009, Anders Eurenius <an...@snowmen.se> wrote:
> Hi
>
>  I have a bit of a problem: the site I'm trying to test uses js to frob a
>  cookie to communicate state, so I'd really like to be able to do that in
>  my test as well. Setting a cookie manager cookie to a script fragment
>  doesn't seem to do it, particularly since I don't want to magically have
>  the cookie before the server sets it. In short:
>
>  ...
>  jmeter: req /able  (no cookie.)
>  server: ok,        cookie: fnord=1234deadbeef
>  ...magic goes here...
>  jmeter: req /baker cookie: fnord=1234deadbeef,{"json":"wierdness"}
>  server: ok...
>  ...
>
>  Using a BSF preprocessor to clobber the variable-by-that-name doesn't
>  seem to work. (I'm guessing it just creates a new variable that shadows
>  the cookie.)

Cookie values are copied to variables but the Cookie Manager does not
use the variable when sending cookies.

>  I could start hacking in Java, but I'd prefer to avoid it.

You will need to write some code.

The only way to change the value of a cookie is to either write your
own copy of the Cookie Manager, or write a Pre-Processor that changes
the value stored by the Cookie Manager.

You can get to the Cookie Manager using sampler.getCookieManager().
After that you'll need to find the cookie and change its value. See
the CookieManager code for details.

Or you could just add a new Cookie with the appropriate details.

>  Thank you.
>
>  Anders Eurenius
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org