jmeter
jmeter copied to clipboard
Checkbox expression not evaluating for the `${__P(property_name)}` and `${variable_name}`
Expected behavior
Use Expression
feature in certain checkboxes in JMeter should evaluate ${__P(property_name)}
and ${variable_name}
value in GUI and CLI.
Expected output for the below steps:
<?xml version="1.0" encoding="UTF-8"?>
<testResults version="1.2">
<httpSample t="61" it="0" lt="58" ct="35" ts="1691114579605" s="true" lb="T00_HomePage_${variable_name}" rc="200" rm="OK" tn="Thread Group 1-1" dt="text" by="1591" sby="109" ng="1" na="1">
<responseData class="java.lang.String"><!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
div {
width: 600px;
margin: 5em auto;
padding: 2em;
background-color: #fdfdff;
border-radius: 0.5em;
box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
}
a:link, a:visited {
color: #38488f;
text-decoration: none;
}
@media (max-width: 700px) {
div {
margin: 0 auto;
width: auto;
}
}
</style>
</head>
<body>
<div>
<h1>Example Domain</h1>
<p>This domain is for use in illustrative examples in documents. You may use this
domain in literature without prior coordination or asking for permission.</p>
<p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>
</responseData>
<cookies class="java.lang.String"></cookies>
<method class="java.lang.String">GET</method>
<queryString class="java.lang.String"></queryString>
<java.net.URL>http://example.com/</java.net.URL>
</httpSample>
<httpSample t="18" it="0" lt="18" ct="0" ts="1691114580766" s="true" lb="T00_HomePage_${variable_name}" rc="200" rm="OK" tn="Thread Group 1-1" dt="text" by="1591" sby="109" ng="1" na="1">
<responseData class="java.lang.String"><!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
div {
width: 600px;
margin: 5em auto;
padding: 2em;
background-color: #fdfdff;
border-radius: 0.5em;
box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
}
a:link, a:visited {
color: #38488f;
text-decoration: none;
}
@media (max-width: 700px) {
div {
margin: 0 auto;
width: auto;
}
}
</style>
</head>
<body>
<div>
<h1>Example Domain</h1>
<p>This domain is for use in illustrative examples in documents. You may use this
domain in literature without prior coordination or asking for permission.</p>
<p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>
</responseData>
<cookies class="java.lang.String"></cookies>
<method class="java.lang.String">GET</method>
<queryString class="java.lang.String"></queryString>
<java.net.URL>http://example.com/</java.net.URL>
</httpSample>
</testResults>
Actual behavior
Use Expression
feature in certain checkboxes in JMeter not evaluating ${__P(property_name)}
and ${variable_name}
value in GUI and CLI.
Steps to reproduce the problem
- Create a simple test plan with one HTTP sampler.
- In
Test Plan
element, right click onFunctional Test Mode
and selectUse Expression
as shown below.
3. Add
${__P(func_mode)}
in the editable checkbox field.
- Save the test plan.
- Add the following property in
jmeter.properties
jmeter.save.saveservice.output_format=xml
- Launch the command prompt.
- Run the script with the below arguments.
jmeter.bat -n -t .\use-expression-checkboxes-demo.jmx -f -l run.xml -Jfunc_mode=true
8. Once the test is done. Open the run.xml.
9. It should have detailed response data. But it contains only the basic info.
<?xml version="1.0" encoding="UTF-8"?>
<testResults version="1.2">
<httpSample t="66" it="0" lt="62" ct="40" ts="1691113938503" s="true" lb="T00_HomePage_${variable_name}" rc="200" rm="OK" tn="Thread Group 1-1" dt="text" by="1591" sby="109" ng="1" na="1">
<java.net.URL>http://example.com/</java.net.URL>
</httpSample>
<httpSample t="17" it="0" lt="17" ct="0" ts="1691113939618" s="true" lb="T00_HomePage_${variable_name}" rc="200" rm="OK" tn="Thread Group 1-1" dt="text" by="1591" sby="109" ng="1" na="1">
<java.net.URL>http://example.com/</java.net.URL>
</httpSample>
</testResults>
Sample observation for ${variable_name}
as well. But true
or false
is working fine as it is enabling/disabling the mode.
JMeter Version
5.6.2
Java Version
openjdk version "11" 2018-09-25
OS Version
Windows 11 22H2 22621.2070
The value gets cached in https://github.com/apache/jmeter/blob/c94db9741f0547235f9a67b1ece40389add6b742/src/core/src/main/java/org/apache/jmeter/testelement/TestPlan.java#L49
Let us replace the cached value with access to isFunctionalMode
. For instance, we could add TestPlan
to JmeterContext
, and use JMeterContextService.getContext().getTestPlan().isFunctionalMode()
in the current TestPlan.getFunctionalMode()
method.
Could you prepare a PR?