A J
A J

Reputation: 1545

API testing using jmeter

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. enter image description here

enter image description here

enter image description here enter image description here

Upvotes: 2

Views: 286

Answers (2)

Dmitri T
Dmitri T

Reputation: 168147

  1. 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.

  2. 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
      
    • restart JMeter to pick the property up
    • that's it, now you should have all incoming cookies stored as JMeter Variables with COOKIE_ prefix

      enter image description here

Upvotes: 3

M Navneet Krishna
M Navneet Krishna

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.

enter image description here

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,

enter image description here

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.

enter image description here

The cookie value is captured and available for utilization. This is visible in the Debug Sampler.

enter image description here

For additional information on how to do correlation using regular expression extractor, use this link How to do Correlation

Hope this helps!

Upvotes: 0

Related Questions