JMeter – How To Clear All Results using BeanShell Code with Example

Spread the love

Here you can learn how to write a BeanShell code that call during the JMeter test run and Clear required Listener Results. Please use below code, copy and paste into your JMeter BeanSheel code area and Save JMeter and Run it. You can see that when this code calls in JMeter during the test run, it will clean all test results.

import org.apache.jmeter.gui.GuiPackage;
import org.apache.jmeter.gui.JMeterGUIComponent;
import org.apache.jmeter.gui.tree.JMeterTreeNode;
import org.apache.jmeter.samplers.Clearable;
 
log.info("Clearing All ...");
 
guiPackage = GuiPackage.getInstance();
 
guiPackage.getMainFrame().clearData();
for (JMeterTreeNode node : guiPackage.getTreeModel().getNodesOfType(Clearable.class)) {
    JMeterGUIComponent guiComp = guiPackage.getGui(node.getTestElement());
    if (guiComp instanceof Clearable){
        Clearable item = (Clearable) guiComp;
        try {
            item.clearData();
        } catch (Exception ex) {
            log.error("Can't clear: "+node+" "+guiComp, ex);
        }
    }
}

Thanks for reading this, if you are itnerested to more, then you may read BeanShell Code to Get Current Date

Spread the love

One Reply to “JMeter – How To Clear All Results using BeanShell Code with Example”

Leave a Reply

Your email address will not be published. Required fields are marked *