Using Beanshell sampler return value in JMeter while condition

1.3k Views Asked by At

image

I am trying to use the return value from beanshell sampler, later in the while condition ${__javaScript(${homeState}<6)}.

When i run and check logs, ${homeState} is not getting replaced with the beanshell sampler homeState integer value.

Can any one suggest what's wrong going on?

however, when i check the response of beanshell sampler in view results tree, it is returing integer as expected.

1

There are 1 best solutions below

3
On

return keyword in Beanshell defines Beanshell sampler response data. If you need to store the value into a JMeter Variable you should replace the line return homeState with the following expression:

vars.put("homeState", String.valueOf(homeState));

vars is a shorthand to JMeterVariables class instance, it provides read/write access to the JMeter Variables in scope.

See How to Use BeanShell: JMeter's Favorite Built-in Component article for comprehensive information on using Beanshell scripting in JMeter tests