четверг, 18 января 2018 г.

jMeter. Gettings variables and their values

This piece of advice came from one of discussions on StackOverflow. Seems to be helpful for some tasks, so putting it here.

Sometimes its extremely valuable to have a chance to pull from the jMeter project all the pre-defined variables and their values. These cases are - but not limited to - exploration existent big jMeter project, debugging issues, intermediate checks of changes made to a project and so on. 

I used to get Set of vars right through the code (variant with Java code in JSR223 PostProcessor):

1. Add "JSR223 PostProcessor" by right click wherever you need to check jMeter variables in your project:


Adding JSR223 PostProcessor

2. Set Language, in my case - to java;

3. Add following code to Script window:
import java.util.Map;
String jMeterVars;
jMeterVars = "Quantity of vars: " + vars.entrySet().size() + ".\n";
jMeterVars += "[VARIABLE NAME] ==>> [VARIABLE VALUE]\n";
for (Map.Entry entry : vars.entrySet()) {
    jMeterVars += entry.getKey() + " ==>> " + entry.getValue().toString() + "\n";
    }

    try {
        FileWriter fw = new FileWriter("D:\\jMeterVarsForStackOverflow.txt",true);
        fw.write(jMeterVars);
        fw.close();
        } catch(IOException ioe) {
            System.err.println("IOException: " + ioe.getMessage());
            }
5. Check that everything in the JSR223 PostProcessor looks like that:

JSR223 PostProcessor ready to go

6. Start your project in jMeter. The code above will create jMeterVarsForStackOverflow.txt file at root of D: and put all variables there:

Sample of file with jMeter variables got by the code above

Комментариев нет:

Отправить комментарий