I'm trying to programmatically traverse all elements (Controllers, Managers, Samplers, etc) in an existing jmeter jmx file, but every example resource I'm finding only allows me to traverse all of a given element in one big Collection cluster (without maintaining the hierarchical ordering).
So far I have the following:
JMeterUtils.loadJMeterProperties(".../jmeter-3.0/bin/jmeter.properties");
JMeterUtils.setJMeterHome(".../apache-jmeter-3.0");
JMeterUtils.initLogging();
JMeterUtils.initLocale();
SaveService.loadProperties();
HashTree testPlanTree = SaveService.loadTree(new File(".../example.jmx"));
SearchByClass<ThreadGroup> threadGroups = new SearchByClass<>(ThreadGroup.class);
testPlanTree.traverse(threadGroups);
Collection<ThreadGroup> threadGroupsRes = threadGroups.getSearchResults();
for (ThreadGroup threadGroup : threadGroupsRes) {
/* Gets me the main ThreadGroups for the test plan, but can't find a way
to traverse the threadGroup to find its Managers, Controllers,
Sub-Controllers, Response Assertions, etc */
}
SearchByClass<LoopController> controllerGroups = new SearchByClass<>(LoopController.class);
testPlanTree.traverse(controllerGroups);
Collection<LoopController> loopControllers = controllerGroups.getSearchResults();
for(LoopController loopController : loopControllers){
/* Gets every LoopController in the test plan but I can't find
a way to determine what its parent and children elements are */
}
Our jmx file is very complex and uses several of the elements available with jmeter including Sub-Controllers and I'd ultimately like to be able to parse and re-compile the jmx with any needed changes (while maintaining the same hierarchy) but have not found many resources that fully explain the Jmeter java API.
<hashTree>all the way down :) - Kiril S.