jmeter icon indicating copy to clipboard operation
jmeter copied to clipboard

Checkbox expression not evaluating for the `${__P(property_name)}` and `${variable_name}`

Open QAInsights opened this issue 1 year ago • 1 comments

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">&lt;!doctype html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Example Domain&lt;/title&gt;

    &lt;meta charset=&quot;utf-8&quot; /&gt;
    &lt;meta http-equiv=&quot;Content-type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot; /&gt;
    &lt;style type=&quot;text/css&quot;&gt;
    body {
        background-color: #f0f0f2;
        margin: 0;
        padding: 0;
        font-family: -apple-system, system-ui, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Open Sans&quot;, &quot;Helvetica Neue&quot;, 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;
        }
    }
    &lt;/style&gt;    
&lt;/head&gt;

&lt;body&gt;
&lt;div&gt;
    &lt;h1&gt;Example Domain&lt;/h1&gt;
    &lt;p&gt;This domain is for use in illustrative examples in documents. You may use this
    domain in literature without prior coordination or asking for permission.&lt;/p&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.iana.org/domains/example&quot;&gt;More information...&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</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">&lt;!doctype html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Example Domain&lt;/title&gt;

    &lt;meta charset=&quot;utf-8&quot; /&gt;
    &lt;meta http-equiv=&quot;Content-type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot; /&gt;
    &lt;style type=&quot;text/css&quot;&gt;
    body {
        background-color: #f0f0f2;
        margin: 0;
        padding: 0;
        font-family: -apple-system, system-ui, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Open Sans&quot;, &quot;Helvetica Neue&quot;, 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;
        }
    }
    &lt;/style&gt;    
&lt;/head&gt;

&lt;body&gt;
&lt;div&gt;
    &lt;h1&gt;Example Domain&lt;/h1&gt;
    &lt;p&gt;This domain is for use in illustrative examples in documents. You may use this
    domain in literature without prior coordination or asking for permission.&lt;/p&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.iana.org/domains/example&quot;&gt;More information...&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</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

  1. Create a simple test plan with one HTTP sampler.
  2. In Test Plan element, right click on Functional Test Mode and select Use Expression as shown below.

image 3. Add ${__P(func_mode)} in the editable checkbox field.

image

  1. Save the test plan.
  2. Add the following property in jmeter.properties jmeter.save.saveservice.output_format=xml
  3. Launch the command prompt.
  4. 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

QAInsights avatar Aug 04 '23 02:08 QAInsights

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?

vlsi avatar Aug 08 '23 06:08 vlsi