2

How can I add a NonTestElement Proxy recording controller in a Jmeter project using Java api? I am trying to do it in THIS GITHUB PROJECT but it is not working. I am able to add a RecordingController, which is a container that stores the recorded items, but I am having trouble adding the non-test recording element to the test plan root element. When I try to add the Proxy controller, it appears as a regular target RecordingController, which is not my intention.

I am using Jmeter 4.0:

// this RecordingController works fine
RecordingController recordingController = new RecordingController();
recordingController.setName("Recordings");
recordingController.setProperty(TestElement.TEST_CLASS, RecordController.class.getName());
recordingController.setProperty(TestElement.GUI_CLASS, TestPlanGui.class.getName());

// this non-test ProxyControl is the one i cant get working
ProxyControl proxyController = new ProxyControl();
proxyController.setName("Proxy Recorder");
proxyController.setProperty(TestElement.TEST_CLASS, ProxyControl.class.getName());
proxyController.setProperty(TestElement.GUI_CLASS, TestPlanGui.class.getName());

ThreadGroup threadGroup = new ThreadGroup();
threadGroup.setName("Sample Thread Group");
....

TestPlan testPlan = new TestPlan("Create JMeter Script From Java Code");
testPlan.setProperty(TestElement.TEST_CLASS, TestPlan.class.getName());
testPlan.setProperty(TestElement.GUI_CLASS, TestPlanGui.class.getName());
testPlan.setUserDefinedVariables((Arguments) new ArgumentsPanel().createTestElement());

testPlanTree.add(testPlan);
testPlanTree.add(proxyController);

HashTree threadGroupHashTree = testPlanTree.add(testPlan, threadGroup);
threadGroupHashTree.add(recordingController);

NOTE: while I look for an answer, I verify this actually worked by opening the resulting .jmx project file (generated from this Java code; see link to my project) in Jmeter 4.0. If that doesn't work, then I don't consider this question answered.

djangofan
  • 28,471
  • 61
  • 196
  • 289

1 Answers1

1

Your code is not working, the right way to add proxy controller with the right GUI class proxyController.setProperty(TestElement.GUI_CLASS, ProxyControlGui.class.getName());

Here's a working sample based on your code:

    RecordingController recordingController = new RecordingController();
    recordingController.setName("Recordings");
    recordingController.setProperty(TestElement.TEST_CLASS, RecordController.class.getName());
    recordingController.setProperty(TestElement.GUI_CLASS, RecordController.class.getName());

    ProxyControl proxyController = new ProxyControl();
    proxyController.setName("Proxy Recorder");
    proxyController.setProperty(TestElement.TEST_CLASS, ProxyControl.class.getName());
    proxyController.setProperty(TestElement.GUI_CLASS, ProxyControlGui.class.getName());

    ThreadGroup threadGroup = new ThreadGroup();
    LoopController loopController = new LoopController();
    loopController.setLoops(1);
    loopController.setFirst(true);
    loopController.setProperty(TestElement.TEST_CLASS, LoopController.class.getName());
    loopController.setProperty(TestElement.GUI_CLASS, LoopControlPanel.class.getName());
    loopController.initialize();
    // Thread Group

    threadGroup.setName("Sample Thread Group");
    threadGroup.setNumThreads(1);
    threadGroup.setRampUp(1);
    threadGroup.setSamplerController(loopController);
    threadGroup.setProperty(TestElement.TEST_CLASS, ThreadGroup.class.getName());
    threadGroup.setProperty(TestElement.GUI_CLASS, ThreadGroupGui.class.getName());

    TestPlan testPlan = new TestPlan("Create JMeter Script From Java Code");
    testPlan.setProperty(TestElement.TEST_CLASS, TestPlan.class.getName());
    testPlan.setProperty(TestElement.GUI_CLASS, TestPlanGui.class.getName());
    testPlan.setUserDefinedVariables((Arguments) new ArgumentsPanel().createTestElement());
    testPlan.addTestElement(proxyController);
    HashTree testPlanTree = new HashTree();
    testPlanTree.add(testPlan);

    HashTree threadGroupHashTree = testPlanTree.add(testPlan, threadGroup);
    threadGroupHashTree.add(recordingController);
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • Just tried your suggestion and it doesn't work. I'll look some more this weekend because there must be a solution. Maybe I will also try a different version of Jmeter but I doubt that will be the solution as I am using the 4.0 java api... – djangofan Mar 01 '18 at 16:32
  • Can you write what is the error or not working. Because it works in my side. Do you expect it to execute a recording? Or you want to save to jmx file? – Ori Marko Mar 01 '18 at 17:18
  • I want to save to a .jmx file, which it does, but I need Jmeter 4.0 to be capable of opening that file (as validation the format is correct). – djangofan Mar 04 '18 at 21:54