One of my friends wanted to access the cookie data that was generated from the cookie manager in Jmeter. So I googled a lot and couldn't find much information to achieve this. So in this post I will explain how I got this soloved.
Note : I tried to do this with a Regular Expression Extractor without any lick. It oesn't provide a option to access cookie data.
So the Simplest way I could do this is by using a JSR223 PreProcessor. Same thing can be achieved with a BeanShell preProcessor as well.
So Fist we need to access the current sampler context. This can be done by ctx.getCurrentSampler() and then lets get the cookie Manager. ctx.getCurrentSampler().getCookieManager().get(0) Note that you have to parse the index to the get method to get the cookie and I have passed 0 here. So the full syntax will look like following.
String cookie = ctx.getCurrentSampler().getCookieManager().get(0).toString();
Now lets assign this value to a Jmeter variable. This can be done in the following manner.
vars.put("jsessionid2",cookie);
The full Sampler will look like following.
So that's it, After getting the Cookie data you can perform any operation of the extracted string. Please drop a comment if you have any other queries.