47

So after executing a test run, I have the Aggregate Report's table filled with the data of the test plan that just finished running. Now, when I execute the test plan again, the results are getting added to this data in the Aggregate Report's table, but I would like the table data to be cleaned up before starting to display the results for the current run. Any way to do this?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Srikanth
  • 11,780
  • 23
  • 72
  • 92

3 Answers3

74

Jmeter does not have a flag to do this automatically.

Generally, you have to clear the results with CTRL+E (in windows) or from the file menu, under RUN > CLEAR or RUN > CLEAR ALL

You might be able to write a beanshell script to clear the results everytime you execute the script.

http://www.javadocexamples.com/java_examples/org/apache/jmeter/samplers/SampleListener/

BlackGaff
  • 7,579
  • 1
  • 38
  • 45
  • That didn't work. Ctrl+C is a shortcut for the copy command. And I don't see a menu option to clear it from the File menu, either. – Srikanth Feb 07 '11 at 05:55
  • My mistake...should have been CTRL+E. In the file menu, it's RUN > CLEAR or RUN > CLEAR ALL – BlackGaff Feb 07 '11 at 15:50
  • That worked. Sorry for the late answer. Pretty stupid of me, actually. Can't figure out how I missed something so obvious. – Srikanth Feb 28 '11 at 10:31
  • What do you mean "Jmeter does not have a flag to do this automatically"? Or in other words where exactly would this flag be? – Willa Feb 18 '16 at 15:38
13

Here is a Beanshell script that will clear the results everytime you execute it:

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);
        }
    }
}

To use this Beanshell script in your JMeter Script :

1) Select the root node of your JMeter Script, and, using the mouse menu, add a setup node :

   Add / Threads (Users) / setup Thread Group

2) Select the newly created node, and using the mouse menu, add a script node :

   Add / Samplers / Beanshell Sampler

3) Finally, copy and paste the above script into the Script window.

Ingo Jobling
  • 138
  • 1
  • 5
  • 1
    This very useful beanshell will fail if Jmeter is run headless as the gui components don't exist. However, if you wrap this beanshell in an If Controller you can check for a variable that only exists from the command-line, and then you can keep the script in your tests whether gui or headless. – Aidan Jun 30 '17 at 00:48
4

Note: Manual procedure to achieve this via GUI functions is given below.

The Clear option is available under the Run menu.

Function Windows Keyboard Shortcut macOS Keyboard Shortcut
Clear CTRL+SHIFT+E +SHIFT+E
Clear All CTRL+E +E
Saikat
  • 14,222
  • 20
  • 104
  • 125