How to save response in a variable in jmeter

I am doing load testing on my server using jmeter. In one of my mail requests, I get a unique identifier in the response. I need to send this identifier as a parameter to the following mail requests. I am new to jmeter and don't know how to do this. Help will be really appreciated.

+5
source share
3 answers

If you need to save the whole answer in a variable, follow these steps:


Alternatively, you can do the same with Extractor Regular Expression, in which case the appropriate configuration would be:

  • Reference Name: response
  • Regular expression: (?s)(^.*)
  • Template: $1$

If you need a part of the answer, and not the whole answer, you can change the regular expression according to your needs according to Regular Expressions in the chapter of JMeter User Guide

+5
source

You can use the JMeter Post-Processor Regular Expression Extractor to extract the required value from the response. Just add this under the sampler, the response of which will contain the required value.

In the extrovert of a Reg expression, you define the variable name (referenceName), RegularExpression, template, etc. Later you can use the value in this variable. To learn how to use the Reg expression extractor, you can refer to the following guide.

https://docs.blazemeter.com/customer/portal/articles/1743642-using-regex-regular-expression-extractor-with-jmeter

+4
source

If you really need to save the whole answer in a variable, do the following:

JSR223 Post Processor

  1. Place the following line in the "Script" area:

vars.put ("response", prev.getResponseDataAsString ());

  1. Use this answer as $ {response} where you need it

But you rarely have to use the whole answer, and you should avoid it for large ones, in which case it is much better to use an Extractor that matches your response:

+1
source

Source: https://habr.com/ru/post/1239202/


All Articles