2

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!

strauberry
  • 4,189
  • 5
  • 34
  • 50

2 Answers2

1

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

RaGe
  • 22,696
  • 11
  • 72
  • 104
1

For Beanshell feel free to use any approach you like.

For JSR223 Test Elements and Groovy language which is recommended way of doing scripting in your JMeter test - avoid refering JMeter Variables and Functions using ${this way} as it prevents script from compilation and causes execution overhead. See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! article for more detailed explanation, different scripting approaches benchmark and scripting best practices.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133