apache / jmeter

Apache JMeter open-source load testing tool for analyzing and measuring the performance of a variety of services
https://jmeter.apache.org/
Apache License 2.0
8.36k stars 2.1k forks source link

Harmonize keys for bindings (i. e. JSR223-Elements) #6368

Open dgetzlaf opened 2 hours ago

dgetzlaf commented 2 hours ago

Expected behavior

When shifting my test setup from JSR223Asstions to JSR223Listener (with the same groovy code) I can execute the same code without errors.

Code:

...
if (!vars.get("login_session")?.trim() && ctx.getCurrentSampler().getName().contains("0030_Do Authenticate")) {
    SampleResult.setResponseMessage("login_session not returned by step 0030")
    SampleResult.setSuccessful(false)
}
...

Actual behavior

When "blindly" shifting and executing the code I get the error:

ERROR o.a.j.v.JSR223Listener: Problem in JSR223 script, Handle Results
javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: SampleResult for class: Script28

When diving into the code, I noticed that sampleResult and SampleResult are used: sampleResult in JSR223Listener and JavaScript SampleResult in JSR223Sampler and JSR223Assertion

It would be nice to have the same bindings within all languages and elements (Groovy, Jexl, JavaScript, Assertions, Listeners, ...)

Steps to reproduce the problem

Run this code in JSR223 Assertion and in JSR223 Listener

if (!vars.get("login_session")?.trim() ) {
    SampleResult.setResponseMessage("login_session not returned by step 0030")
    SampleResult.setSuccessful(false)
}

JMeter Version

5.6.3

Java Version

openjdk version "21.0.2" 2024-01-16 LTS

OS Version

Microsoft Windows [Version 10.0.19045.5011]

dgetzlaf commented 2 hours ago

For example you can use this simple testplan: Issue 6368.jmx.txt