2

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

Matt
  • 413
  • 1
  • 10
  • 16
  • Looks like this could be a bug, see this link [BUG-28715](https://bz.apache.org/bugzilla/show_bug.cgi?id=28715). Anyone else experience this? – Matt Apr 28 '15 at 20:48
  • 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 Apr 28 '15 at 21:11
  • Have a look at this to add cookie. http://stackoverflow.com/questions/13680350/how-to-set-cookie-in-jmeter-that-is-usually-set-via-javascript – vins Apr 28 '15 at 21:17
  • 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 Apr 28 '15 at 21:39
  • 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 Apr 28 '15 at 21:43
  • Do you have a space between -J & myProp? send it like this `-JmyProp=val` – vins Apr 28 '15 at 21:57
  • But, it seems to print in BeanShell only if I capture the properties variable inside a User Defined Variable first using the same "${__P()}" statement, and then using vars.get inside BeanShell to capture that... So I can get to the properties variable through a User-Defined Variable, but cannot get to the properties variable directly from BeanShell... Weird, is that expected? – Matt Apr 28 '15 at 22:17

1 Answers1

3

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

vins
  • 15,030
  • 3
  • 36
  • 47
  • Hey Vinoth, thanks for the reply and taking the time to test it out, much appreciated! Humm, ok I'll give it another shot, I'm pretty sure my test was setup pretty much in the same way. I'm running JMeter Version **Version 2.13 r1665067**, are you running the same..? Thanks Again! – Matt Apr 29 '15 at 14:34
  • I have 2.11 - but it should be ok. Please start with user defined variables. – vins Apr 29 '15 at 14:35
  • Hey @Vinoth S, so I just tried again and had this in my CookieManager for the Cookie's value **${__P(myCookie.var)}**. BTW, I found a Plugin for JMeter called Property FIle Reader which is a Config Element for defining a User Properties file within the GUI. So I used that bc running from CLI I couldn't see that Request Tab of the Tree Viewer to see the cookies used. This time I used that and defined my prop var and running the test I could see that value being used as the Cookie correctly, but BeanShell prints this as the value for the Cookie --> **${__P(myCookie.var)}** while looping through – Matt Apr 29 '15 at 15:13
  • Hi..it is a double underscores. ${__P()} – vins Apr 29 '15 at 15:19
  • Just tried again, this time using User-Defined Var in Cookie Manager and the Prop Var as the User-Defined Var's value. And the Request Tab shows the correct cookie, but BeanShell is again printing it like this for some reason: `2015/04/29 11:16:49 INFO - jmeter.util.BeanShellTestElement: Cookie.getValue() = '${userVar}'`... But I have no idea why it would be showing that as the **Value** for the Cookie..? – Matt Apr 29 '15 at 15:19
  • how do you use it in beanshell? – vins Apr 29 '15 at 15:37
  • I am using double underscores,something must be happening when I copy and paste it.... But I am definitely using double underscores. I uploaded a couple of Screenshots to PhotoBucket of my Test Plan. You can see it [HERE](http://i1326.photobucket.com/albums/u658/mrm5102/CookieManager_Screenshot_zpsohfxlslt.png~original).. In that you'll see the CookieManager, User_Defined Vars, BeanShell and Log Viewer so you can see what BeanShell is printing. Thanks Again! – Matt Apr 29 '15 at 15:55
  • In that Screenshot, you'll see the BeanShell code. That BeanShell code is from a PreProcessor. But, I also just tried it in a PostProcessor and it prints that same thing `Cookie.getValue() = '${userVar}'` along with 2 other Cookies that are set automatically from the website. – Matt Apr 29 '15 at 16:01
  • I apologize, I just noticed the screenshot from the link in my Comment had a shot of my disabled CookieManager in which I was trying to use the properties var in.This link here is to the [Correct Image](http://i1326.photobucket.com/albums/u658/mrm5102/CookieManager_Screenshot_zps37log5ng.png) which has the shot of the actual CookieManager being used... Again Sorry about that. – Matt Apr 29 '15 at 17:04
  • I think I'm going to post a new question... I'm finding some more problems with this and I don't want to get too far off my original topic. – Matt Apr 29 '15 at 18:07
  • @Matt, may be this is expected. - it stores the value as it is. replaces with appropriate value while sending the sampler. – vins Apr 29 '15 at 18:09
  • Yea I'm not sure if that is supposed to be doing that or what. But I wanted to be able to check the cookies before and after the HTTP Request runs and verify that the Cookie was NOT changed automatically by the WebServer/HAProxy. But, its looking like I may have to set the Cookie programmatically inside a BeanShell in order for me to do what I was hoping to do... I have also noticed using **vars.get("COOKIE_MYID")** and printing it to the log prints **null** as its value in BSH, but if I print for example **COOKIE_JSESSIONID** which gets set automatically, that works just fine. Thanks Again! – Matt Apr 29 '15 at 18:57