1

I'm looking for a way to reuse User Defined Variables and Uses of said variables in a way that doesn't require repeating them in every JMeter test, I fear this isn't possible.

For example we've defined a few User Defined Variables (with more planned):

      <Arguments guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
    <collectionProp name="Arguments.arguments">
      <elementProp name="SERVER" elementType="Argument">
        <stringProp name="Argument.name">SERVER</stringProp>
        <stringProp name="Argument.value">${__P(server,localhost)}</stringProp>
        <stringProp name="Argument.metadata">=</stringProp>
      </elementProp>
      <elementProp name="PORT" elementType="Argument">
        <stringProp name="Argument.name">PORT</stringProp>
        <stringProp name="Argument.value">${__P(port,80)}</stringProp>
        <stringProp name="Argument.metadata">=</stringProp>
      </elementProp>
      <elementProp name="PATH" elementType="Argument">
        <stringProp name="Argument.name">PATH</stringProp>
        <stringProp name="Argument.value">${__P(path,)}</stringProp>
        <stringProp name="Argument.metadata">=</stringProp>
      </elementProp>
      <elementProp name="LOOPS" elementType="Argument">
        <stringProp name="Argument.name">LOOPS</stringProp>
        <stringProp name="Argument.value">${__P(loops,1)}</stringProp>
        <stringProp name="Argument.metadata">=</stringProp>
      </elementProp>
      <elementProp name="THREADS" elementType="Argument">
        <stringProp name="Argument.name">THREADS</stringProp>
        <stringProp name="Argument.value">${__P(threads,1)}</stringProp>
        <stringProp name="Argument.metadata">=</stringProp>
      </elementProp>
      <elementProp name="RAMPSECONDS" elementType="Argument">
        <stringProp name="Argument.name">RAMPSECONDS</stringProp>
        <stringProp name="Argument.value">${__P(rampseconds,1)}</stringProp>
        <stringProp name="Argument.metadata">=</stringProp>
      </elementProp>
      <elementProp name="USERPREFIX" elementType="Argument">
        <stringProp name="Argument.name">USERPREFIX</stringProp>
        <stringProp name="Argument.value">${__P(userprefix,testuser)}</stringProp>
        <stringProp name="Argument.metadata">=</stringProp>
      </elementProp>
      <elementProp name="COUNTERCONFIGSTART" elementType="Argument">
        <stringProp name="Argument.name">COUNTERCONFIGSTART</stringProp>
        <stringProp name="Argument.value">${__P(counterconfigstart,1)}</stringProp>
        <stringProp name="Argument.metadata">=</stringProp>
      </elementProp>
      <elementProp name="COUNTERCONFIGEND" elementType="Argument">
        <stringProp name="Argument.name">COUNTERCONFIGEND</stringProp>
        <stringProp name="Argument.value">${__P(counterconfigend,6)}</stringProp>
        <stringProp name="Argument.metadata">=</stringProp>
      </elementProp>
      <elementProp name="COUNTERCONFIGINCR" elementType="Argument">
        <stringProp name="Argument.name">COUNTERCONFIGINCR</stringProp>
        <stringProp name="Argument.value">${__P(counterconfigincr,1)}</stringProp>
        <stringProp name="Argument.metadata">=</stringProp>
      </elementProp>
    </collectionProp>
  </Arguments>

And then use them:

  <ConfigTestElement guiclass="HttpDefaultsGui" testclass="ConfigTestElement" testname="HTTP Request Defaults" enabled="true">
    <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
      <collectionProp name="Arguments.arguments"/>
    </elementProp>
    <stringProp name="HTTPSampler.domain">${SERVER}</stringProp>
    <stringProp name="HTTPSampler.port">${PORT}</stringProp>
    <stringProp name="HTTPSampler.connect_timeout"></stringProp>
    <stringProp name="HTTPSampler.response_timeout"></stringProp>
    <stringProp name="HTTPSampler.protocol"></stringProp>
    <stringProp name="HTTPSampler.contentEncoding"></stringProp>
    <stringProp name="HTTPSampler.path">${PATH}</stringProp>
    <stringProp name="HTTPSampler.concurrentPool">4</stringProp>
  </ConfigTestElement>
  ....
  <CounterConfig guiclass="CounterConfigGui" testclass="CounterConfig" testname="USER Counter" enabled="true">
    <stringProp name="CounterConfig.start">${COUNTERCONFIGSTART}</stringProp>
    <stringProp name="CounterConfig.end">${COUNTERCONFIGEND}</stringProp>
    <stringProp name="CounterConfig.incr">${COUNTERCONFIGINCR}</stringProp>
    <stringProp name="CounterConfig.name">USER</stringProp>
    <stringProp name="CounterConfig.format">${USERPREFIX}</stringProp>
    <boolProp name="CounterConfig.per_user">false</boolProp>
  </CounterConfig>
0

I ended up extracting the last few differences in our JMeter tests to User Defined Variables and then defined the variables in a csv file and used the JMeter's CSV Data Set.

However, when running on Jenkins the test results are then in 1 log file and hence 1 graph, which isn't what we want. We want 1 graph per page under test. So I used Freemarker to generate separate tests one for each line in the csv file. Since JMeter and Freemarker use the same variable notation ( ${myvariable} ) I replaced all the JMeter ${ with @{ which are then replaced after the Freemarker templating is done.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.