Erfan Tavoosi
Erfan Tavoosi

Reputation: 419

JMeter: The purpose of User-defined Cookies for requests

I'm just trying to get going with JMeter, and I try to understand more about User-defined cookies.

What purpose do they fulfill when you add them with hard-coded values, like for instance if you define a cookie called A and give it a value B to a certain domain for your HTTP sampler?

Much grateful for all information!

Upvotes: 0

Views: 99

Answers (2)

Ori Marko
Ori Marko

Reputation: 58822

Some web sites have Javascript scripts executed on page load which are adding/removing/updating HTTP cookie(s)

The set() method of the cookies API sets a cookie containing the specified cookie data. This method is equivalent to issuing an HTTP Set-Cookie header during a request to a given URL.

JMeter isn't executing Javascript

JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages.

So in JMeter you can manually manipulate HTTP cookie as you expect your site to execute

Upvotes: 0

Dmitri T
Dmitri T

Reputation: 168122

There could be several possible reasons:

  1. Replay user session without having to re-login (i.e. session hijacking) so you would be able to debug your test by running a single request rather than the whole sequence (open login page, login, navigate somewhere, do something, etc.)
  2. The value doesn't have to be hard-coded, it may come from correlation or calculation by the JSR223 Pre-Processor
  3. Negative test scenarios (providing invalid cookie value to check for anticipated error)
  4. You name it

Upvotes: 1

Related Questions