Home > Software design >  Conversion Error in JMeter through Java. What dependencies are missing?
Conversion Error in JMeter through Java. What dependencies are missing?

Time:10-21

From https://www.blazemeter.com/blog/5-ways-launch-jmeter-test-without-using-jmeter-gui, I have this test file:

public class JMeterTests {
    StandardJMeterEngine jmeter;
    HashTree testPlanTree;
    
    @BeforeEach
    void init() throws Exception {
        // JMeter Engine
        jmeter = new StandardJMeterEngine();

        // Initialize Properties, logging, locale, etc.
        JMeterUtils.loadJMeterProperties("src/test/java/com/tests/JMeterTests.java");
        JMeterUtils.setJMeterHome("/usr/local/Cellar/jmeter/5.4.1");
        JMeterUtils.initLocale();

        // Initialize JMeter SaveService
        SaveService.loadProperties();

        // Load existing .jmx Test Plan
        FileInputStream in = new FileInputStream("src/test/jmeter/my.jmx");
        testPlanTree = SaveService.loadTree(in); // <-- testPlanTree is null, did not load
        in.close();
    }

    @Test
    void fromExistingJmx() throws MalformedURLException {
        // Run JMeter Test
        jmeter.configure(testPlanTree); // <-- Fails since testPlanTree is null
        jmeter.run();
    }
}

As a result, I get this error:

ERROR   2021-10-19 13:29:31.301 [jmeter.s] (): Conversion error com.thoughtworks.xstream.converters.ConversionException: org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor : org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor
---- Debugging information ----
message             : org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor
cause-exception     : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message       : org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor
class               : org.apache.jorphan.collections.ListedHashTree
required-type       : org.apache.jorphan.collections.ListedHashTree
converter-type      : org.apache.jmeter.save.converters.HashTreeConverter
path                : /jmeterTestPlan/hashTree/hashTree/hashTree[4]/hashTree/JSONPostProcessor
line number         : 207

I've already confirmed my.jmx works in GUI mode.

CodePudding user response:

From https://www.blazemeter.com/blog/5-ways-launch-jmeter-test-without-using-jmeter-gui, you have the following statement:

Have the required JMeter jars from /lib and especially /lib/ext folders of your JMeter installation in your project or module class path.

If it is not clear enough get Apache JMeter Components » 5.4.1 library in your project classpath

Also you made a mistake in copying and pasting this line:

JMeterUtils.loadJMeterProperties("src/test/java/com/tests/JMeterTests.java");

it should point to jmeter.properties file, preferably the original one.

  • Related