Varun Sharma
Varun Sharma

Reputation: 1752

JMeter reponse headers values before redirection on status code 302

I am performing load testing on an API using JMeter. For that, I call an oauth link, which returns a code in the headers which I use for further testing. But the link redirects to another link and I am unable to capture the value of the response headers when a response with status code 302 is returned. How can I do that.

Upvotes: 0

Views: 2452

Answers (2)

Dmitri T
Dmitri T

Reputation: 168157

If your situation is like this one:

JMeter Redirect

You can still extract the dynamic value from the latter sample result by modifying Regular Expression Extractor scope

As per documentation:

Apply to:

This is for use with samplers that can generate sub-samples, e.g. HTTP Sampler with embedded resources, Mail Reader or samples generated by the Transaction Controller.

  • Main sample only - only applies to the main sample

  • Sub-samples only - only applies to the sub-samples

  • Main sample and sub-samples - applies to both.

  • JMeter Variable - assertion is to be applied to the contents of the named variable

By default Regular Expression Extractor is looking into Main sample only, in the above example it is HTTP Request, if the data you're looking for is stored in one of the sub-samples it is enough to change Regular Expression Extractor's scope to look into sub-results as well:

JMeter RegEx Sub Results

Upvotes: 1

timbre timbre
timbre timbre

Reputation: 13995

You have 2 options:

  1. Do not allow HTTP request to redirect. Simply uncheck "Follow Redirects" checkbox in the HTTP Sampler:

    enter image description here

    That way you can process this request normally. The drawback is of course that you need to add a second request which will take you to a link to which you are normally redirected automatically.

  2. Most post-processors allow you to extract value from either main sample, or sub-samples, or both. So follow redirect as before, but change Post-Processor to extract value from sub-sample. For example Regular Expression Extractor:

    enter image description here

Upvotes: 0

Related Questions