'How to append Http Response to a Jmeter variable
I need to append response from set of http requests and assert response. Example
Request1-> Response is "Anil"
Request2-> Response is "Sunil"
Request3-> Response is "Kumar"
Request4-> Response is "Tej"
I need to create a global variable "GlobalRespone". Append and store all response to this variable ex: GlobalResponse = "Anil,Sunil,Kumar,Tej" So that I can write the custom validation rule at Request4 which will pass the Request4 if GlobalResponse contains "Sunil" or else fail the sampler.
How can we achieve this? appreciate if any one can help.
Solution 1:[1]
Add JSR223 PostProcessor at the same level as all your requests
Put the following code into "Script" area:
vars.put('GlobalRespone', (vars.get('GlobalRespone') ?: '') + prev.getResponseDataAsString())
Add Response Assertion as a child of the last request
Configure it as follows:
The JSR223 PostProcessor will append to the variable GlobalRespone
the response data of each Sampler in its scope and the Response Assertion will check whether this variable contains Sunil
Demo:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dmitri T |