Search code examples
jmeterbeanshell

JMeter - HTTP request does not see variable defined in BS PreProcessor


Having defined HTTPRequest with BeanShellPreProcessor with following code:

log.info(vars.get("view_state"));
props.put("view_state", vars.get("view_state"));

Following with configuration of HTTP Request which is: enter image description here

enter image description here

However, the final request does not recognize this parameter and shows this:

...&javax.faces.ViewState=%24%28view_state%29...

Question is why it is not recognized as variable ?


Solution

  • You are putting values into JMeter Properties and trying to read them from JMeter Variables. Properties and Variables are different beasts and need to be accessed differently.

    The solutions are in:

    1. Change your props.put statement to vars.put (the other syntax remains the same).varsis a shorthand to JMeterVariables class, using it you will manipulate JMeter Variables instead of properties
    2. Leave your Beanshell script intact and access the value from property using __P() function like ${__P(view_state)}

    More information: How to Use BeanShell: JMeter's Favorite Built-in Component