Search code examples
jmeter

JMeter Switch Controller, Parameters and User-Defined Variables


My objective is to create a JMX that can be run from the terminal with a parameter specifying the environment, defaulting to "local". The environment specifies which list of user-defined variables is to be active.

I've set up a Switch Controller with UDV lists as children.

enter image description here

enter image description here

I'm setting the switch value to ${__P(env,"local")} and my expectation is that the UDV with the matching name (default of "local") will be active. What ends up happening is that whatever the final UDV within the Switch Controller is, that will be active. If "local" is last, that will always be used, if "qa" is last, that will always be used. I've tried setting up Simple Controllers as children to the Switch Controller and that doesn't make a difference.

What am I missing here?


Solution

  • As per User Defined Variables documentation:

    The User Defined Variables element lets you define an initial set of variables, just as in the Test Plan.

    Note that all the UDV elements in a test plan - no matter where they are - are processed at the start.

    If you need to use this or that set of variables depending on the environment you can create it either using Set Variables Action or JSR223 Sampler. In the latter case you can use vars shorthand for JMeterVariables class instance like:

    vars.put('oauth.host', 'foo')
    vars.put('oauth.client_id', 'bar')
    //etc