jmetercommentsexecutejsr223

Code in JMeter JSR223 Sampler comments is executed


Please tell me why the code in comments (both /*something*/ and //something) is executed using JSR223 Sampler & BeanShell sampler? For example, I have: enter image description here

and in the next JSR223 Sampler I have:

enter image description here

and the result is:

enter image description here

and the question is: why this code: "/${__setProperty(checkProperty, 50)};/" is executed regardless of that it is in comment and it is in wrong condition?


Solution

  • JMeter Functions are being executed in the place where they're found, no matter where it is, in Sampler label, comments section, sampler body, etc.

    Actually inlining JMeter Functions and/or Variables into JSR223 scripts is not the best idea as

    So if you need to set a property - use props.put() function like

    props.put('foo', 'bar')
    

    And finally I'm not sure that using props.clear() is a good idea because there are some pre-defined JMeter properties (you can check yourself using Debug Sampler and View Results Tree listener combination) and it might result into unexpected behaviour if a test element will be relying on that property existence and/or value

    enter image description here