Is it possible to add test elements on the fly to JMeter with Java code?

I'm being able to create jmx files by using Java code, those output files contain elements such as test plan and samplers; however, I'm running an initialization routine that loads variables from disk and should create/configure new samplers based on that. I don't know how to access the running test plan element or add new sampler elements on the fly though.

Is it something possible to do? I've been browsing the API docs but haven't found a way to do it yet.

javajmeter

Answers

answered 2 years ago Hassen Bennour #1

it is possible to add new elements on the fly but these new elements will not be executed because the StandardJMeterEngine is started and not aware of them unless you restart the test. you can create one test containing the routines and create another test plans from a template that you modify, save and run.

another solution is to work only with Variables loaded by the routine

this method provide the possibility to access the testplan at runtime and modify their childs elements

 org.apache.jmeter.gui.GuiPackage.getInstance().getTreeModel().getTestPlan();

to execute a test :

FileInputStream in = new FileInputStream(testPlanPath);
HashTree testPlanTree = SaveService.loadTree(in);
in.close();
StandardJMeterEngine jmeter = new StandardJMeterEngine();
jmeter.configure(testPlanTree);
jmeter.runTest();

Do not hesitate if you need more informations.

comments powered by Disqus