I am fairly new to Jmeter and hence having trouble figuring out the following: I am testing a web service that needs a valid cookie to be sent in header. I have an endpoint url against which the userid and password validates. How do I validate the credentials against the url and extract the cookie for the user and send it in header for the request in Jmeter?
5
votes
1 Answers
7
votes
JMeter provides HTTP Cookie Manager which automatically handles cookies so in the majority of cases you don't need to do anything apart from adding the HTTP Cookie Manager to your Test Plan
However in some cases, i.e. in some CSRF implementations you need to add a request header holding previous response specific cookie value. In that case you should be acting like:
Add the next line to user.properties file (lives in JMeter's "bin" folder
CookieManager.save.cookies=true
- Restart JMeter to pick the property up. The above setting "tells" JMeter to store cookie values as JMeter Variables prefixed by
COOKIE_
. So for example if you have cookie with the name offoo
you will be able to access its value as${COOKIE_foo}
- Add HTTP Header Manager and set it up to send the desired header using
${COOKIE_foo}
as a value (replacefoo
with your actual cookie name)
More detailed information: Using the HTTP Cookie Manager in JMeter