Search code examples
javaswingjmeterjmeter-plugins

JMeter How to add a Test element dynamically/programmatically?


I have the JMeter code, (https://jmeter.apache.org/svnindex.html).

In JMeter we can add testelements by right clicking on test plan>add>.... I want to automate this adding of a testelement (eg: Regular expression extractor) to the testplan. Means, I have a button on my HTTP request form (or any testelement). Upon clicking the button a regular expression extractor should be added in the testplan tree as a child of the HTTP request. Could you please help me?

package org.apache.jmeter.extractor.gui.RegexExtractorGui is the class for regular expression extractor gui.

Thanks.


Solution

  • I got the solution for my Question from AddToTree of org.apache.jmeter.gui.action package as guiPackage.getTreeModel().addComponent(testElement, parentNode);

    Here, guiPackage is an instance of org.apache.jmeter.gui.GuiPackage class.

    Testelement can be created using guiPackage.createTestElement(classname).

    guiPackage.getCurrentNode() will provide currently selected node.

    finally guiPackage.getTreeModel().addComponent(testElement, parentNode) will add the testelement as a child of parent node.

    Thank u