wmitchell
wmitchell

Reputation: 5725

jmeter - counting cookie values

I'm playing around with jmeter to validate a bug fix.

Server logic sets the cookie "mygroup" it can be either "groupa" or "groupb". I want to be able fire a series of requests and be able to see there is a proper balanced distribution between the values of this cookie. Ie make 100 requests and 50 times the cookie will be set to "groupa" and "groupb".

I'm a bit stuck on this. I currently have the following. I can see the cookies being set in the results tree but I'd like to be able to display the a table with the version and the number of requests of each.

Thread Group
    HTTP Cookie Manager
    HTTP Request
    View Results Tree 

Within the results tree I can see Set-Cookie: mygroup="groupa" and also sometimes mygroup="groupb" how do I tabulize this ??

Upvotes: 0

Views: 806

Answers (1)

UBIK LOAD PACK
UBIK LOAD PACK

Reputation: 34526

You can have cookies values exported as JMeter variables by setting: CookieManager.save.cookies=true

in user.properties.

Add a Cookie Manager to your Test Plan.

In this case you will have the var COOKIE_mygroup set by JMeter.

You can then count it like this using a JSR223 Sampler + Groovy (add groovy-all-version.jar in jmeter/lib folder:

    String value = vars.get("COOKIE_mygroup");
    Integer counterB = vars.getObject("counterB");
    Integer counterA = vars.getObject("counterA");
    if(counterA == null) {
        counterA = new Integer(0);
        vars.putObject("counterA", counterA);
    }
    if(counterB == null) {
        counterB = new Integer(0);
        vars.putObject("counterB", counterB);
    }
    if(value.equals("groupa")) {
        counterA = counterA+1;
        vars.putObject("counterA", counterA);
    } else {
        counterB = counterB+1;
        vars.putObject("counterB", counterB);

    }

Asyou have only one thread, at end of loop you can then compare the 2 values or just display the value:

  • add a debug sampler

  • add a view tree result

Run test plan, in view result tree click on debug sampler , select response tab and you should have your values

Upvotes: 1

Related Questions