Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract Location from Response Header with JMeter

I have this string :

Location →/cochise/workflow/5c46e69364ddf300013412b5

How do I extract the final hexadecimal code using jmeter?

like image 202
Francesco Portgas D. Cottardo Avatar asked Jan 22 '19 09:01

Francesco Portgas D. Cottardo


2 Answers

Add a Regular Expression Extractor post processor as a child of your request with below configurations:

  • Apply to: Main sample and sub-samples
  • Field to check: Response Headers
  • Reference Name: myVar
  • Regular Expression: Location: .+\/(.*?)\n
  • Template: $1$
  • Match No: 1
  • Default Value: NOT_FOUND

Now you can use jmeter variable ${myVar} which contains hexadecimal value. You can add view results tree and debug sampler at thread group level to make sure you are extracting the right value.

References

  • Regular expressions from Jmeter user manual.
  • Using regex with jmeter
like image 183
ararar Avatar answered Sep 28 '22 10:09

ararar


The easiest is going for the Regular Expression Extractor

  1. Add Regular Expression Extractor as a child of the request which returns the above header
  2. Configure it as follows:

    enter image description here

    for your convenience here is the textual form of the regular expression:

    /cochise/workflow/(.*)
    
  3. That's it, you should now be able to access the extracted value as ${foo} where required.

  4. Also be aware that you can test your regular expressions via RegExp Tester mode of the View Results Tree listener. This approach in conjunction with i.e. Dummy Sampler can greatly speed up scripts development process as you will not have to re-run the entire scenario in order to test an extractor:

    enter image description here

like image 44
Dmitri T Avatar answered Sep 28 '22 08:09

Dmitri T