Tanmay Bhattacharya
Tanmay Bhattacharya

Reputation: 551

JSR223 sampler jmeter / Passing cookie data

I am trying to simulate a parallel ajax requests using a JSR223 sampler, as mentioned here https://www.blazemeter.com/blog/how-load-test-ajaxxhr-enabled-sites-jmeter

But for my set of requests ,I am getting an error,Invalid API/Auth Key I assume it is is becuase the authentication cookie is not being passed ,I tried to grab the cookie from the previous sampler using

HTTPSamplerProxy previousSampler = ctx.getPreviousSampler();
CookieManager cookieManager = previousSampler.getCookieManager();
HTTPSampleResult previousResult = (HTTPSampleResult)ctx.getPreviousResult();
log.info("Cookie Count is : "+ cookieManager.getCookieCount());

But I get the error

Cannot invoke method getCookieCount() on null object

,I do have the cookie manager enabled in my test plan.

Any help on what I am doing wrong would be great .

Upvotes: 0

Views: 397

Answers (1)

Dmitri T
Dmitri T

Reputation: 168147

The error you're getting means that there is no HTTP Cookie Manager associated with the sampler. You need to add it to your Test Plan and your code should start working as expected.


Be aware that as of now there is a much easier way to implement AJAX requests without having to do any coding, there is Parallel Controller which can be used to mimic AJAX calls by running its children in parallel. Just add it to your Test Plan and move HTTP Request samplers which represent AJAX calls under it. See How to Use the Parallel Controller in JMeter for more details if needed.

Upvotes: 0

Related Questions