0

I have a loop controller with an If controller inside of it. The if controller triggers on certain loop iterations to update a Jmeter variable (SystemId). The If controller and groovy script seem to work correctly, however, outside of the if controller the Jmeter variable (SystemId) seems to reset to the value before the If controller executed?

I have put debug samplers/post processors to check the state of the Jmeter variables inside and outside the if controller. The debug inside the loop shows the SystemId variable updated the very next element is the outside sampler which shows the SystemId reverted to the previous value.

Samplers

I have tried various java, groovy, and beanshell approaches to changing the variable. All work with the sampler inside the if controller showing the variable changed, but all still result in the variable value being reverted outside of the if controller as shown by the sampler outside the if controller.

Edit: Added if controllers and debug sampler/postprocessors

            <IfController guiclass="IfControllerPanel" testclass="IfController" testname="If2 Controller">
              <stringProp name="IfController.condition">&quot;${SysCounter}&quot;==&quot;2&quot;</stringProp>
              <boolProp name="IfController.evaluateAll">false</boolProp>
              <boolProp name="IfController.useExpression">false</boolProp>
            </IfController>
            <hashTree>
              <JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="If2 set SystemId">
                <stringProp name="scriptLanguage">groovy</stringProp>
                <stringProp name="parameters"></stringProp>
                <stringProp name="filename"></stringProp>
                <stringProp name="cacheKey">true</stringProp>
                <stringProp name="script">vars.put(&quot;SystemId&quot;,vars.get(&quot;BellowsId&quot;))</stringProp>
              </JSR223Sampler>
              <hashTree>
                <DebugPostProcessor guiclass="TestBeanGUI" testclass="DebugPostProcessor" testname="If2 Inside Debug">
                  <boolProp name="displayJMeterProperties">false</boolProp>
                  <boolProp name="displayJMeterVariables">true</boolProp>
                  <boolProp name="displaySamplerProperties">true</boolProp>
                  <boolProp name="displaySystemProperties">false</boolProp>
                </DebugPostProcessor>
                <hashTree/>
              </hashTree>
            </hashTree>
            <DebugSampler guiclass="TestBeanGUI" testclass="DebugSampler" testname="Outside If2 Debug">
              <boolProp name="displayJMeterProperties">false</boolProp>
              <boolProp name="displayJMeterVariables">true</boolProp>
              <boolProp name="displaySystemProperties">false</boolProp>
            </DebugSampler>

1 Answer 1

0

We cannot provide a comprehensive answer without seeing your full test plan, which groovy scripts you're using, what is the If Controller's condition, how do you set the variable, etc.

As per documentation JMeter Variables are local to the thread so:

  • the variables are not shared between virtual users
  • once the variable is set it will have the value until the user is shut down or it's overwritten with a new value

So it shouldn't be the case that the variable has one value inside the If Controller and another value outside the If Controller, you need to search your test plan for any occurrences of setting the value of the variable and check how many times the code is called and by which test element. You can enable JMeter debug logging to see what's going on under the hood

Sign up to request clarification or add additional context in comments.

1 Comment

My script is rather involved, I edited my question to contain the if controller and the debug postprocessor/sampler. The debug postprocessor "If2 Inside Debug" shows the value of SystemId being changed as desired. However, the "Outside If2 Debug" and all further references to SystemId seem to revert to the value prior to the If Controller's chagne.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.