简体   繁体   English

如何使用 Java api 在 Jmeter 项目中添加 RecordingController?

[英]How can I add a RecordingController in a Jmeter project using Java api?

How can I add a NonTestElement Proxy recording controller in a Jmeter project using Java api?如何使用 Java api 在 Jmeter 项目中添加NonTestElement代理记录控制器? I am trying to do it in THIS GITHUB PROJECT but it is not working.我试图在这个 GITHUB 项目中做到这一点,但它不起作用。 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.我可以添加一个 RecordingController,它是一个存储记录项目的容器,但我无法将非测试记录元素添加到测试计划根元素。 When I try to add the Proxy controller, it appears as a regular target RecordingController, which is not my intention.当我尝试添加代理控制器时,它显示为常规目标 RecordingController,这不是我的意图。

I am using Jmeter 4.0:我正在使用 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.注意:在我寻找答案时,我通过在 Jmeter 4.0 中打开生成的 .jmx 项目文件(从此 Java 代码生成;请参阅我的项目的链接)来验证这是否确实有效。 If that doesn't work, then I don't consider this question answered.如果那不起作用,那么我认为这个问题没有答案。

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());您的代码不起作用,添加具有正确 GUI 类的代理控制器的正确方法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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Java从Jmeter API创建Jmeter脚本时,如何添加基本身份验证? - How to add Basic Authentication while creating Jmeter Script from Jmeter API using java? 如何在Json中使用jmeter添加随机值 - How can i add random value using jmeter in Json JMeter RecordingController 记录不同格式的请求 - JMeter RecordingController Record Request In Different Formats 如何使用Java在jmeter api中为testPlan或线程组添加所需的侦听器? - How to add required listeners for testPlan or thread group in jmeter api using java? 如何使用 JMeter 登录 SalesForce? - How can I log into SalesForce using JMeter? 如何使用Java代码从Jmeter API使用吞吐量整形计时器? - How will I use Throughput Shaping Timer from Jmeter API using java code? 我将如何使用 Java 代码从 Jmeter API 使用像 GraphiteBackendListenerClient 和 InfluxdbBackendListenerClient 这样的 BackendListenerClient? - How will I use BackendListenerClient like GraphiteBackendListenerClient and InfluxdbBackendListenerClient from Jmeter API using java code? jmeter - 如何存储来自第一个请求的数据并使用 java 代码将其传递给第二个请求 - jmeter - How can I store data from first request and pass it to second request using java code 如何使用Java Jmeter API依次遍历所有Jmeter测试计划元素 - How to traverse all Jmeter test plan elements in order using java jmeter API 如何通过使用JMeter API从JAVA类获取Jmeter测试结果 - how to get Jmeter test result from JAVA Class by using JMeter API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM