Jmeter JEMETER非GUI:缺少类com.thoughtworks.xstream.converters.ConversionException错误

Jmeter JEMETER非GUI:缺少类com.thoughtworks.xstream.converters.ConversionException错误,jmeter,jmeter-3.2,Jmeter,Jmeter 3.2,我正在从头开始创建JMeter测试计划。 这是我的密码: public static void main(String[] args) throws Exception { StandardJMeterEngine jmeterEngine = new StandardJMeterEngine(); JMeterUtils.setJMeterHome("/Users/myDir/Documents/JMeter/apache-jmeter-3.3");

我正在从头开始创建JMeter测试计划。 这是我的密码:

public static void main(String[] args) throws Exception {

        StandardJMeterEngine jmeterEngine = new StandardJMeterEngine();
        JMeterUtils.setJMeterHome("/Users/myDir/Documents/JMeter/apache-jmeter-3.3");
        JMeterUtils.loadJMeterProperties("src/main/resources/jmeter.properties");
        JMeterUtils.initLocale();

        //create test plan
        TestPlan testPlan = new TestPlan();
        testPlan.setEnabled(true);
        testPlan.setName("Test Plan");

        //create thread group
        ThreadGroup threadGroup = new ThreadGroup();
        threadGroup.setNumThreads(1);
        threadGroup.setRampUp(1);

        // create http sampler
        HTTPSampler httpSampler = new HTTPSampler();
        httpSampler.setProtocol("https");
        httpSampler.setDomain("myDomain.services.company.com");
        httpSampler.setPath("ims/login/v1/token");
        httpSampler.setMethod("POST"); 
        httpSampler.setFollowRedirects(true);
        httpSampler.setAutoRedirects(false);
        httpSampler.setUseKeepAlive(true);
        httpSampler.addArgument("client_id", "argValue1");
        httpSampler.addArgument("scope", "argValue2");
        httpSampler.addArgument("userName", "abc%2B249%40gmail.com");
        httpSampler.addArgument("password", "Abc123"); 

        //Add sampler to the thread group
        threadGroup.addTestElement(httpSampler);

        HashTree testPlanHashTree = new HashTree();
        testPlanHashTree.add(testPlan);
        testPlanHashTree.add(threadGroup);

        // Generating the JMX file
        SaveService.saveTree(testPlanHashTree, new FileOutputStream(JMeterUtils.getJMeterHome() + "/bin/Test2.jmx"));
    }
当我执行这段代码时,就会创建Test2.jmx

接下来,我尝试使用以下命令通过Jmeter的非GUI模式运行Test2.jmx:

./jmeter.sh-n-t Test2.jmx

Jmeter没有运行测试计划,而是抛出以下错误:

Error in NonGUIDriver java.lang.IllegalArgumentException: Problem loading XML from:'/Users/chandrat/Documents/JMeter/apache-jmeter-3.3/bin/Test2.jmx', missing class com.thoughtworks.xstream.converters.ConversionException: 
---- Debugging information ----
cause-exception     : com.thoughtworks.xstream.converters.ConversionException
cause-message       : 
first-jmeter-class  : org.apache.jmeter.save.converters.HashTreeConverter.unmarshal(HashTreeConverter.java:67)
class               : org.apache.jmeter.save.ScriptWrapper
required-type       : org.apache.jmeter.threads.ThreadGroup
converter-type      : org.apache.jmeter.save.ScriptWrapperConverter
path                : /jmeterTestPlan/org.apache.jorphan.collections.HashTree/org.apache.jorphan.collections.HashTree/ThreadGroup
line number         : 6
version             : 3.3 r1808647
-------------------------------
1) 我不知道如何解决这个问题?原因消息为空?我应该怎样做才能在没有上述错误的情况下执行我的测试计划

2) 您还可以看看我的测试计划生成代码吗?那代码对吗?测试组应该直接添加到树中还是首先添加到测试计划中,然后再将测试计划添加到树中

以下是pom文件中的依赖项,以防我丢失一个jar

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.jmeter</groupId>
        <artifactId>ApacheJMeter_core</artifactId>
        <version>3.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.jmeter</groupId>
        <artifactId>jorphan</artifactId>
        <version>3.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.jmeter</groupId>
        <artifactId>ApacheJMeter_http</artifactId>
        <version>3.3</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.6</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.7</version>
    </dependency>
    <dependency>
        <groupId>oro</groupId>
        <artifactId>oro</artifactId>
        <version>2.0.8</version>
    </dependency>
    <dependency>
        <groupId>org.apache.avalon.framework</groupId>
        <artifactId>avalon-framework-api</artifactId>
        <version>4.3.1</version>
    </dependency>
  </dependencies>

朱尼特
朱尼特
3.8.1
测试
org.apache.jmeter
ApacheJMeter_核心
3.3
org.apache.jmeter
乔芬
3.3
org.apache.jmeter
ApacheJMeter_http
3.3
公地io
公地io
2.6
org.apache.commons
commons-lang3
3.7
奥罗
奥罗
2.0.8
org.apache.avalon.framework
avalon框架api
4.3.1

请帮忙。谢谢

为了能够在JMeter GUI中打开生成的测试计划,您需要定义更多的属性,修改代码如下:

public static void main(String[] args) throws Exception {

    StandardJMeterEngine jmeterEngine = new StandardJMeterEngine();
    JMeterUtils.setJMeterHome("/Users/myDir/Documents/JMeter/apache-jmeter-3.3");
    JMeterUtils.loadJMeterProperties("src/main/resources/jmeter.properties");
    JMeterUtils.initLocale();

    //create test plan
    TestPlan testPlan = new TestPlan();
    testPlan.setEnabled(true);
    testPlan.setName("Test Plan");
    testPlan.setProperty(TestElement.TEST_CLASS, TestPlan.class.getName());
    testPlan.setProperty(TestElement.GUI_CLASS, TestPlanGui.class.getName());
    testPlan.setUserDefinedVariables((Arguments) new ArgumentsPanel().createTestElement());

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

    //create thread group
    ThreadGroup threadGroup = new ThreadGroup();
    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());

    // create http sampler
    HTTPSampler httpSampler = new HTTPSampler();
    httpSampler.setProtocol("https");
    httpSampler.setDomain("myDomain.services.company.com");
    httpSampler.setPath("ims/login/v1/token");
    httpSampler.setMethod("POST");
    httpSampler.setFollowRedirects(true);
    httpSampler.setAutoRedirects(false);
    httpSampler.setUseKeepAlive(true);
    httpSampler.addArgument("client_id", "argValue1");
    httpSampler.addArgument("scope", "argValue2");
    httpSampler.addArgument("userName", "abc%2B249%40gmail.com");
    httpSampler.addArgument("password", "Abc123");
    httpSampler.setProperty(TestElement.TEST_CLASS, HTTPSampler.class.getName());
    httpSampler.setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());

    //Add sampler to the thread group

    HashTree testPlanHashTree = new HashTree();
    HashTree threadGroupHashTree = testPlanHashTree.add(testPlan, threadGroup);
    threadGroupHashTree.add(httpSampler);

    // Generating the JMX file
    SaveService.saveTree(testPlanHashTree, new FileOutputStream(JMeterUtils.getJMeterHome() + "/bin/Test2.jmx"));
}
参考资料:

  • 示例项目

谢谢你,德米特里。你的代码可以工作。我是Jmeter的新手,所以我有几个问题将进一步澄清我的概念:1)你能解释一下关于哈希树的行吗?(我知道哈希树是什么,但是)为什么在这里使用它,以及如何使用它?为什么我们需要分别使用testPlanHashTree和threadGroupHashTree?发生的事情是这样一行:HashTree threadGroupHashTree=testPlanHashTree.add(testPlan,threadGroup);?接下来,如果我需要向我的httpSampler添加一个元素,比如HeaderManager,我必须为我的httpSampler创建一个单独的hashtree。我的头管理器将添加到哪里?接下来,如果我需要向我的httpSampler添加一个元素,比如HeaderManager,我必须为我的httpSampler创建一个单独的hashtree。我的主管经理将添加到哪里?