2

I've a BeanShell Assertion within a HTTP Request sampler:

enter image description here

The previous result can be obtained using the script ctx.getPreviousResult(), but how can we get the result before the previous result?

  • E.g. to achieve something alike if (previousResult.previousResult.getResponseCode().equals("202")) {... – Pacerier Oct 8 '15 at 10:37
1

It is not possible to get "older" sample result than previous result is always previous and when next sampler is being executed it's being overwritten by current, etc.

You can use bsh.shared namespace to hold the "interesting" sampler result. In order to do so add Beanshell PostProcessor as a child of the sampler, which result you need to store and put the following code into "Script" area:

bsh.shared.result = prev;

In your Beanshell Assertion you will be able to get response code as:

String code = bsh.shared.result.getResponseCode();
if (code.equals("202")) {
    //do what you need
} 

Demonstration:

bsh.shared.namespace.demo

See How to Use BeanShell: JMeter's Favorite Built-in Component guide for more Beanshell tips and tricks.

  • Is this the only way to do it? Seems odd that there's no inbuilt mechanism to reference previous results (since results are often interlinked). – Pacerier Oct 11 '15 at 7:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.