0
votes

I don't want this to be part of any sampler (i.e pre-processor; post-processor). I simply want to start my thread group (which will loop) and check if a couple cookies exist. If they don't, I will login. If they do, I will run the rest of my tests and loop again.

enter image description here

I've tried several different things. The two methods I see for pulling the cookie manager is:

CookieManager cm = ctx.getCurrentSampler().getCookieManager();

and

CookieManager cm = sampler.getCookieManager();

I keep getting the error:

javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method getCookieManager() on null object

I've created a JSR223 pre-processor, post-processor, and assertion and none of them seem to work.

I just want the cookies that are currently stored in the HTTP Cookie Manager which is global to the thread. There is no associated sampler. Why in the world are these methods related to a specific sampler when the cookie manager isn't even local to the sampler? I'm checking the cookies BEFORE I run any sampler.

1

1 Answers

0
votes

Most probably you're violating JMeter Scoping Rules or Test Elements Execution Order, it is quite hard to tell what's wrong as your screenshot doesn't demonstrate full structure of the test plan. None of pre/post processors or assertions will work without sampler :

enter image description here

Actually you don't even need any scripting, if you add the next line to user.properties file:

CookieManager.save.cookies=true

then you will get cookies exposed in form of ${COOKIE_XXX} where XXX is the cookie name, the variable can be used i.e. in the If Controller