Search code examples
jmeterbeanshell

What are the pros and cons of using JMeterUtils.getProperty vs. __P in JMeter?


I'm working on some JMeter test plans that employ BeanShell assertions. Within these assertions I want to acess some user properties. There are several ways to access them:

JMeterUtils.getProperty("propertyName")
${__P(propertyName)
props.get("propertyName")

Where are the differences and what are the pros and cons of each option? Are they wrapper of each other or do they have specific functionality?

Thank you!


Solution

  • Functionally they are all exactly the same. They are even implemented the same way - they all call the getProperty() method on the current jmeter properties object.

    The difference is where you use them.

    1. The ${} notation is used when putting variables into JMeter GUI text boxes. In the fields on the HTTP sampler for example. note that __P is shorthand for, and exactly the same as __Property

    2. props.get() is used in beanshell scripts, without having to explicitly import JMeterUtils. You can also combine 1&2 to do ${__BeanShell(props.get())}

    3. If you do import JMeterUtils in beanshell, or you're developing a custom java class, then you would use JMeterUtils.getProperty().

    Of the three, I would think #1 is the most efficient because it doesn't need to instantiate and evaluate beanshell