Skip to content Skip to sidebar Skip to footer

Jmeter Pre-processed Variable As Part Of Report File Name

In my test plan I have JDBC PreProcessor that captures a single value that I'm trying to save into a variable. Then I want to reuse this variable as part of summary report's file n

Solution 1:

Changing filenames of Listeners test elements on the fly is not really supported in JMeter as Listeners are being initialized before any variables. The recommended way is:

  1. Get your Terradata session id outside of JMeter, i.e. using BTEQ or equivalent
  2. Pass the value to JMeter via -J command line argument like:

    jmeter -Jsession_id_1=1234 -n -t /path/to/testplan.jmx
    
  3. Refer the session id value via __P() function where required as

    ${__P(session_id_1,)}
    

If for any reason you still need to do it inside JMeter test script, here is a possible solution, however keep in mind the following:

  1. You need to remove everything from "Filename" input of the Summary Report listener. Just let it be blank.
  2. Make sure that below code is executed only once and with only one thread.

So:

  1. Add JSR223 PostProcessor as a child of the query1 sampler and after the Session PreProcessor
  2. Select groovy in the "Language" drop-down
  3. Put the following code into JSR223 PostProcessor "Script" area:

    import org.apache.jmeter.engine.StandardJMeterEngine;
    import org.apache.jmeter.reporters.ResultCollector;
    import org.apache.jorphan.collections.HashTree;
    import org.apache.jorphan.collections.SearchByClass;
    
    import java.lang.reflect.Field;
    import java.lang.reflect.Method;
    
    StandardJMeterEngineengine= ctx.getEngine();
    Fieldtest= engine.getClass().getDeclaredField("test");
    test.setAccessible(true);
    HashTreetestPlanTree= (HashTree) test.get(engine);        
    
    SearchByClasssummaryReportsSearch=newSearchByClass(ResultCollector.class);
    testPlanTree.traverse(summaryReportsSearch);
    CollectionsummaryReports= summaryReportsSearch.getSearchResults();
    ResultCollectorsummaryReport= summaryReports.iterator().next();
    
    Class [] fileNameParam = newClass[1];
    fileNameParam[0] = String.class;
    
    MethodsetFileName= summaryReport.getClass().getDeclaredMethod("setFilenameProperty", fileNameParam);
    setFileName.setAccessible(true);
    setFileName.invoke(summaryReport, newString(vars.get("session_id_1")));
    
    Methodinit= summaryReport.getClass().getDeclaredMethod("initializeFileOutput");
    init.setAccessible(true);
    init.invoke(summaryReport);
    

If you're using JMeter 3.0 - groovy is bundled. For previous JMeter versions you will need to install groovy language support manually, check out Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! article for groovy engine installation instructions and scripting best practices.

Solution 2:

you cannot use a variable as part of a summary report file name as a variable exist per User thread and after summary report has been initialized.

Use property instead:

Post a Comment for "Jmeter Pre-processed Variable As Part Of Report File Name"