masonje
masonje

Reputation: 49

jmeter prev.getResponseDataAsString getting wrong return

I have a looping process that will extract some values from a web service (working) and loop through to pull all the information for each value (working).

I need to capture the whole return into a variable so I can modify it and post it back up later.

Screenshot:

enter image description here

When the "Baseline for ..." get kicks in, I get the proper response

But the "Get response" BeanShell PreProcessor is picking up old responses

Screenshot:

enter image description here

Given where my "Get response" object is, I would assume the: vars.put("ResponceData", prev.getResponseDataAsString());

...would grab the response from "Baseline for ${ID} of site ${callSite}". Please help!

Upvotes: 0

Views: 7106

Answers (1)

Dmitri T
Dmitri T

Reputation: 168072

You are using wrong test element. Beanshell PreProcessor is being executed before request therefore it acts properly and returns response from the previous request instead of current one. You need to change it to the Beanshell PostProcessor and your code will start working as you expect.


It is recommended to avoid scripting where possible, if you need to save response data into a JMeter Variable you can do it using i.e. Regular Expression Extractor. According How to Extract Data From Files With JMeter article the relevant configuration will be something like:

  • Reference Name: ResponceData
  • Regular Expression: (?s)(^.*)
  • Template: $1$

    JMeter Regular Expression

If you face a JMeter limitation which cannot be worked around without using scripting make sure you are using the most performing scripting language, since JMeter 3.1 it is recommended to use JSR223 Test Elements and Groovy language

Upvotes: 1

Related Questions