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.



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


to execute a test :

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

Do not hesitate if you need more informations.

comments powered by Disqus