Reputation: 1545
I am trying to do some API testing in Jmeter. I was trying to follow this https://octoperf.com/blog/2018/04/23/jmeter-rest-api-testing/ . But I need to get token from cookie.
Can anyone suggest me a solution? Using Jmeter version 5.0
Sorry, if this question was asked previously. But, I could't find a solution.
Upvotes: 2
Views: 286
Reputation: 168147
According to JMeter Best Practices you should always be using the latest version of JMeter so considering migrating to JMeter 5.0 (or whatever latest version is available at JMeter Downloads page) on next available opportunity.
If the value you're looking for comes as a HTTP Cookie - it makes a perfect sense to use HTTP Cookie Manager to get the cookies values
add the next line to user.properties file:
CookieManager.save.cookies=true
that's it, now you should have all incoming cookies stored as JMeter Variables with COOKIE_
prefix
Upvotes: 3
Reputation: 694
The above link uses JSON extractor to correlate the value. As you rightly noticed, the JSON extractor can be used only on the body of the response and not on the headers (cookies mostly appear in the response headers). For this purpose, we will have to revert to our traditional Regular expression extractor.
Select "Field to check" as "Response Headers" and we are good to go. In this case, Regular Expression needs to be utilized for extracting the value and the approach used in the OPs link cannot be leveraged.
For example, if my response headers are as below,
and if I want to capture the NID token which is in line 11 as part of the Set-Cookie parameter, I would use the below Regex.
The cookie value is captured and available for utilization. This is visible in the Debug Sampler.
For additional information on how to do correlation using regular expression extractor, use this link How to do Correlation
Hope this helps!
Upvotes: 0