Jmeter Pre-processed Variable As Part Of Report File Name
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:
- Get your Terradata session id outside of JMeter, i.e. using BTEQ or equivalent
Pass the value to JMeter via -J command line argument like:
jmeter -Jsession_id_1=1234 -n -t /path/to/testplan.jmxRefer 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:
- You need to remove everything from "Filename" input of the Summary Report listener. Just let it be blank.
- Make sure that below code is executed only once and with only one thread.
So:
- Add JSR223 PostProcessor as a child of the
query1sampler and after theSession PreProcessor - Select
groovyin the "Language" drop-down 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"