3

Is there any possibility to iterate or loop through a "User Defined Variables" - set like it's possible with a CSV data set (WHILE-COUNTER-CSV Data Set Config)?

I want to fire a JDBC request (Select Statement) for each variable contained in the "User Defined Variables" - Set. It works fine with a CSV file, but i can't figure out how I can loop through a variables set. Is that even possible? I have various scenarios, where I want to loop through a "User Defined Variables" - set.

2
  • May I know the issue with using CSV Dataset Config? I don't think there is way to iterate through all UDVs Commented Feb 16, 2017 at 8:56
  • I don't want to use CSV's because of multiple reasons: - Im afraid that too much CSV reads have an negative impact on performance of the test - Information isn't centralized in the Testplan, instead I always have to open the CSV files to look for something - Commented Feb 16, 2017 at 9:13

2 Answers 2

7

In order to be able to iterate the User Defined Variables with ForEach Controller you just need to follow simple naming convention like:

  • var_1=someValue
  • var_2=someOtherValue
  • var_3=someMoreValue
  • etc.

However if you would like to keep the original variable names you can create an extra set of JMeter Variables which can be consumed by the ForEach Controller using the next steps:

  1. Let's assume you have the following User Defined Variables:

    JMeter User Defined Variables

    and you want to use their values in ForEach controller

  2. Add JSR223 Test Element (Sampler, Pre/Post Processor, etc) somewhere in your script and put the following code in its "Script" area

    import org.apache.jmeter.threads.JMeterVariables;
    
    int counter = 1;
    
    JMeterVariables tempVars = new JMeterVariables()
    
    vars.entrySet().each { entry -> 
        def name = entry.getKey()
        if (!name.equals("JMeterThread.last_sample_ok") && !name.equals("JMeterThread.pack") && !name.equals("START.HMS") && !name.equals("START.MS") &&
            !name.equals("START.YMD") && !name.equals("TESTSTART.MS")) {
            tempVars.put("tempVar_" + counter, entry.getValue())
            counter++;
        }
    }
    
    vars.putAll(tempVars);
    

    After script finishes you should have 3 more JMeter Variables

    JMeter variables generated by groovy

  3. Once you have them - you can use ForEach Controller configured like:

    ForEach Controller for extra variables

  4. So you will be able to use ${current} (or whatever you put into the "Output variable name" in the JDBC Request

    Groovy Variables substitution

See Groovy Is the New Black article to learn more about using Groovy in JMeter tests.

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

Comments

-5

You can't just iterate within the User defined variables list. From a security perspective you shouldn't be allowed to do that.

You should stick to csv files.

References:

5 Comments

Thank you for your answer. Ok so I need to implement it with CSV's. So do you think it's valid to say, that using UDV's is faster than using CSV data sets, because the CSV hast to be read and the read information has to be stored as a JMeter variable, where UDV's are directly defined JMeter variables?
I understand your point, but the added latency wouldn't decrees your performance much (under 2%) if the file is located on the same machine. I consider it an acceptable loss.
And the queries/ values are much easier to update within a csv file.
I'm with you, it's an acceptable loss. To workaround this affection, I could read all CSV files and data from the database, like described in the question, in my preparation thread group (where i also restore db backups and so on) before the actual test thread group. Or isn't it a good idea to create a large amount of UDV data?
You can chose each way. Reading from file works ok if you have under 10 k rows but that sometimes gets really hard to update.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.