2
votes

I have been reading just about everything I can find on CookieManager and JMeter Variables and Properties and I just can't seem to get it working or if this will even work.

What I want to do is to be able to set the Cookie i want to use on the Command Line and/or from a .properties file.

Inside my Cookie Manager I have manually added one Cookie like so:

CookieManager:
NAME  |       VALUE          |    DOMAIN     |  PATH
------+----------------------+---------------+--------
MYID  | ${__P(myCookie.var)} |  mydomain.com |   /        

Then, what I tried to do was pass a value for "myCookie.var" on the CLI using:

-J "myCookie.var=srv1"

to set the Cookie "MYID", but when I run the case the Cookie is set to 'null'...


When the above did NOT work I tried adding a User Defined Variables element to the Test Plan. I added one variable with NAME = "myVar", and the value set to VALUE = "${__P(myCookie.var)}". Then, in the CookieManager I set it as:

CookieManager:
NAME  |  VALUE   |    DOMAIN     |  PATH
------+----------+---------------+-------
MYID  | ${myVar} |  mydomain.com |   /        


So, after running my Test Plan and checking the variables in a BeanShell I can see that the User-Defined Variable "myVar" is receiving the variable I pass on the Command-Line, but the Cookie "MYID" is still being set to 'null'...

Are Cookie Managers allowed to use variables as the Cookie's VALUE?

Thanks in Advance,
Matt

1
Looks like this could be a bug, see this link BUG-28715. Anyone else experience this? - Matt
I never tried this flow & will see when i find time. Could be a bug as well. The bug seems to be 10 years old. it also says it s fixed. - vins
Have a look at this to add cookie. stackoverflow.com/questions/13680350/… - vins
Yea I saw it said it was fixed which is why this is bugging me soo much! I'm running the newest version available of JMeter 2.13 so this bug should be fixed. I also included the option in jmeter.properties file CookieManager.allow_variable_cookies=true even though its the default behavior but that didn't seem to change anything. For your 2nd comment, I did think of changing the Cookie that way, but I was hoping to do it this way since I could just pass it on the CLI and there would be less moving parts in the test Plan... - Matt
I did try accessing my properties variable by printing it in a BeanShell PreProcessor, but that's not working either. Doing this: log.info("Property: " + ${_P(myProp)}); prints --> "void"... And doing it this way: log.info("Property: " + ${_P("myProp")}); prints --> "1"... Passing this as the Command-Line Option each time "-J 'myProp=srv1''"... - Matt

1 Answers

3
votes

I just tried in JMeter using user defined variables.- able to substitute the user defined variables in Cookie Manager.

It can work fine for properties too. Pass them as given below in the command line option

-JPropName=PropValue

So, in your case, it should be -JmyCookie.var=srv1 (no space , no ").

Access it using ${__P(myCookie.var)}. It should work.

enter image description here

enter image description here

enter image description here