I've a BeanShell Assertion within a HTTP Request sampler:
The previous result can be obtained using the script ctx.getPreviousResult()
, but how can we get the result before the previous result?
I've a BeanShell Assertion within a HTTP Request sampler:
The previous result can be obtained using the script ctx.getPreviousResult()
, but how can we get the result before the previous result?
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:
See How to Use BeanShell: JMeter's Favorite Built-in Component guide for more Beanshell tips and tricks.
if (previousResult.previousResult.getResponseCode().equals("202")) {
...