如何使用 Java api 在 Jmeter 项目中添加 RecordingController?
How can I add a RecordingController in a Jmeter project using Java api?
如何使用Javaapi在Jmeter项目中添加NonTestElement代理记录控制器?我正在尝试在 THIS GITHUB PROJECT 中执行此操作,但它不起作用。我可以添加一个 RecordingController,它是一个存储记录项的容器,但我无法将非测试记录元素添加到测试计划根元素。当我尝试添加 Proxy 控制器时,它显示为常规目标 RecordingController,这不是我的意图。
我正在使用 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);
注意:当我寻找答案时,我通过在 Jmeter 中打开生成的 .jmx 项目文件(从此 Java 代码生成;请参阅我的项目 link)来验证这是否确实有效4.0。如果这不起作用,那么我认为这个问题没有得到回答。
您的代码不工作,使用正确的 GUI 添加代理控制器的正确方法 class proxyController.setProperty(TestElement.GUI_CLASS, ProxyControlGui.class.getName());
这是一个基于您的代码的工作示例:
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);
如何使用Javaapi在Jmeter项目中添加NonTestElement代理记录控制器?我正在尝试在 THIS GITHUB PROJECT 中执行此操作,但它不起作用。我可以添加一个 RecordingController,它是一个存储记录项的容器,但我无法将非测试记录元素添加到测试计划根元素。当我尝试添加 Proxy 控制器时,它显示为常规目标 RecordingController,这不是我的意图。
我正在使用 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);
注意:当我寻找答案时,我通过在 Jmeter 中打开生成的 .jmx 项目文件(从此 Java 代码生成;请参阅我的项目 link)来验证这是否确实有效4.0。如果这不起作用,那么我认为这个问题没有得到回答。
您的代码不工作,使用正确的 GUI 添加代理控制器的正确方法 class proxyController.setProperty(TestElement.GUI_CLASS, ProxyControlGui.class.getName());
这是一个基于您的代码的工作示例:
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);