Jmeter 使用java运行jmx文件

Jmeter 使用java运行jmx文件,jmeter,jmx,Jmeter,Jmx,我使用java代码创建了一个jmx文件。但是当我尝试使用java执行jmx文件时,它抛出了异常。请帮帮我。。我把所有的罐子都加上了。 (NonGUIDriver java.lang.IllegalArgumentException中出错:从“/home/ksahu/MyScreenshots/k.jmx”加载XML时出现问题,转换错误com.thoughtworks.xstream.converters.ConversionException:null:null) 这是我用来生成jmx文件的代码

我使用java代码创建了一个jmx文件。但是当我尝试使用java执行jmx文件时,它抛出了异常。请帮帮我。。我把所有的罐子都加上了。
(NonGUIDriver java.lang.IllegalArgumentException中出错:从“/home/ksahu/MyScreenshots/k.jmx”加载XML时出现问题,转换错误com.thoughtworks.xstream.converters.ConversionException:null:null)

这是我用来生成jmx文件的代码

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.jmeter.control.LoopController;
import org.apache.jmeter.engine.StandardJMeterEngine;
import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.TestPlan;
import org.apache.jmeter.threads.SetupThreadGroup;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.collections.HashTree;


public class jmeterTesting {

    public static void main(String[] args) throws FileNotFoundException, IOException{
        // Engine
        StandardJMeterEngine jm = new StandardJMeterEngine();
        JMeterUtils.setJMeterHome("/home/ksahu/apache-jmeter-2.13");

        // jmeter.properties
        JMeterUtils.loadJMeterProperties("/home/ksahu/apache-jmeter-2.13/bin/jmeter.properties");

        HashTree hashTree = new HashTree();     

        // HTTP Sampler
        HTTPSampler httpSampler = new HTTPSampler();
        httpSampler.setDomain("www.google.com");
        httpSampler.setPort(80);
        httpSampler.setPath("/");
        httpSampler.setMethod("GET");

        // Loop Controller
        TestElement loopCtrl = new LoopController();
        ((LoopController)loopCtrl).setLoops(1);
        ((LoopController)loopCtrl).addTestElement(httpSampler);
        ((LoopController)loopCtrl).setFirst(true);

        // Thread Group
        SetupThreadGroup threadGroup = new SetupThreadGroup();
        threadGroup.setNumThreads(1);
        threadGroup.setRampUp(1);
        threadGroup.setSamplerController((LoopController)loopCtrl);

        // Test plan
        TestPlan testPlan = new TestPlan("MY TEST PLAN");

        hashTree.add("testPlan", testPlan);
        hashTree.add("loopCtrl", loopCtrl);
        hashTree.add("threadGroup", threadGroup);
        hashTree.add("httpSampler", httpSampler);       
        jm.configure(hashTree);



        jm.run();
        System.out.println(hashTree);
        SaveService.saveTree(hashTree,new FileOutputStream("/home/ksahu/MyScreenshots/k.jmx"));
    }
}

尝试在JMeterGUI中打开您的
/home/ksahu/MyScreenshots/k.jmx
。如果它没有打开-代码有问题,则使用生成JMX文件。在这种情况下,使用代码更新您的问题,您过去常常创建
k.jmx
文件

参见第4章
4。通过程序运行JMETER测试(来自JAVA代码)了解详细信息


还有一个示例项目可以作为参考:

尝试在JMeter GUI中打开您的
/home/ksahu/MyScreenshots/k.jmx
。如果它没有打开-代码有问题,则使用生成JMX文件。在这种情况下,使用代码更新您的问题,您过去常常创建
k.jmx
文件

参见第4章
4。通过程序运行JMETER测试(来自JAVA代码)了解详细信息


还有一个示例项目可以作为参考:

您需要将使用java生成的JMX中的文本“org.apache.jorphan.collections.HashTree”更改为“HashTree”。在任何文本编辑器中打开JMX,并按照所述进行替换。如果这还不够,请包括以下步骤

您需要为每个元素显式设置TestElement.ENABLED、TestElement.TEST_类和TestElement.GUI_类。例如,采样器可定义如下

 HTTPSamplerProxy httpSampler = new HTTPSamplerProxy();
        httpSampler.setDomain(DOMAIN);
        httpSampler.setPort(PORT);
        httpSampler.setPath(PATH);
        httpSampler.setMethod(METHOD);
        httpSampler.addArgument("", "${domain}");
        httpSampler.setProperty(TestElement.ENABLED, true);
        httpSampler.setResponseTimeout("20000");
        httpSampler.setProperty(TestElement.TEST_CLASS, HTTPSamplerProxy.class.getName());
        httpSampler .setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());

您需要将使用java生成的JMX中的文本“org.apache.jorphan.collections.HashTree”更改为“HashTree”。在任何文本编辑器中打开JMX,并按照所述进行替换。如果这还不够,请包括以下步骤

您需要为每个元素显式设置TestElement.ENABLED、TestElement.TEST_类和TestElement.GUI_类。例如,采样器可定义如下

 HTTPSamplerProxy httpSampler = new HTTPSamplerProxy();
        httpSampler.setDomain(DOMAIN);
        httpSampler.setPort(PORT);
        httpSampler.setPath(PATH);
        httpSampler.setMethod(METHOD);
        httpSampler.addArgument("", "${domain}");
        httpSampler.setProperty(TestElement.ENABLED, true);
        httpSampler.setResponseTimeout("20000");
        httpSampler.setProperty(TestElement.TEST_CLASS, HTTPSamplerProxy.class.getName());
        httpSampler .setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());

你试过读取堆栈跟踪吗?另外,请附加它。是的,我尝试读取堆栈跟踪。NonGUIDriver java.lang.IllegalArgumentException中的错误:从“/home/ksahu/MyScreenshots/k.jmx”加载XML时出现问题,转换错误com.thoughtworks.xstream.converters.ConversionException:null:nullcause异常:java.lang.NullPointerException原因消息:null类:org.apache.jmeter.protocol.http.sampler.HTTPSampler所需类型:org.apache.jmeter.protocol.http.sampler.HTTPSampler转换器类型:org.apache.jmeter.protocol.http.sampler.HTTPSamplerBaseConverter路径:/jmeterTestPlan/org.apache.jorphan.collections.HashTree/org.apache.jorphan.collections.HashTree/HTTPSampler uuu行号:6 class[1]:org.apache.jorphan.collections.HashTree转换器类型[1]:org.apache.jmeter.save.converters.hashtreeconverter将它们附加到您的问题上。您是否尝试读取堆栈跟踪?另外,请附加它。是的,我尝试读取堆栈跟踪。NonGUIDriver java.lang.IllegalArgumentException中的错误:从“/home/ksahu/MyScreenshots/k.jmx”加载XML时出现问题,转换错误com.thoughtworks.xstream.converters.ConversionException:null:nullcause异常:java.lang.NullPointerException原因消息:null类:org.apache.jmeter.protocol.http.sampler.HTTPSampler所需类型:org.apache.jmeter.protocol.http.sampler.HTTPSampler转换器类型:org.apache.jmeter.protocol.http.sampler.HTTPSamplerBaseConverter路径:/jmeterTestPlan/org.apache.jorphan.collections.HashTree/org.apache.jorphan.collections.HashTree/HTTPSampler uuu行号:6 class[1]:org.apache.jorphan.collections.HashTree转换器类型[1]:org.apache.jmeter.save.converters.hashtreeconverterator将它们附加到您的问题上。我使用上述代码生成jmx文件我尝试通过GUI模式打开它,但它引发异常我使用上述代码生成jmx文件我尝试通过GUI模式打开它,但它引发异常