I am running a .jmx file using JMeter java code in my maven project. I have recorded a .jmx file using blazemeter. Please refer to the below code that I have tried.
package com.solitera.automation.controller; import org.apache.jmeter.engine.StandardJMeterEngine; import org.apache.jmeter.save.SaveService; import org.apache.jmeter.util.JMeterUtils; import org.apache.jorphan.collections.HashTree; import java.io.File; import java.io.FileInputStream; public class JMeterFromExistingJMX { public static void main(String[] argv) throws Exception { // JMeter Engine StandardJMeterEngine jmeter = new StandardJMeterEngine(); // Initialize Properties, logging, locale, etc. JMeterUtils.loadJMeterProperties("D:/apache-jmeter-5.1.1/bin/jmeter.properties"); JMeterUtils.setJMeterHome("D:/apache-jmeter-5.1.1"); JMeterUtils.initLogging();// you can comment this line out to see extra log messages of i.e. DEBUG level JMeterUtils.initLocale(); // Initialize JMeter SaveService SaveService.loadProperties(); // Load existing .jmx Test Plan /* FileInputStream in = new FileInputStream("D:/Ecllipse_project_workspace2/slt_automation/src/test/jmeter/slt_autoMa_Test.jmx"); HashTree testPlanTree = SaveService.loadTree(in); in.close();*/ HashTree testPlanTree = SaveService.loadTree(new File("D:/apache-jmeter-5.1.1/extras/slt_autoMa_Test.jmx")); // Run JMeter Test jmeter.configure(testPlanTree); jmeter.run(); } } After run as a Java Application in eclipse -> Output is :
SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/Users/rajan/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/rajan/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.12.1/log4j-slf4j-impl-2.12.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder] 18:56:16.586 [main] WARN org.apache.jmeter.util.JMeterUtils - Exception 'null' occurred when fetching boolean property:'server.exitaftertest', defaulting to: false 18:56:16.594 [main] WARN org.apache.jmeter.util.JMeterUtils - Exception 'null' occurred when fetching boolean property:'jmeterengine.remote.system.exit', defaulting to: false 18:56:16.594 [main] WARN org.apache.jmeter.util.JMeterUtils - Exception 'null' occurred when fetching boolean property:'jmeterengine.stopfail.system.exit', defaulting to: true 18:56:16.594 [main] WARN org.apache.jmeter.util.JMeterUtils - Exception 'null' occurred when fetching boolean property:'jmeterengine.force.system.exit', defaulting to: false 18:56:16.610 [main] INFO org.apache.jmeter.util.JMeterUtils - Setting Locale to en_IN 18:56:17.109 [main] INFO org.apache.jmeter.save.SaveService - Testplan (JMX) version: 2.2. Testlog (JTL) version: 2.2 18:56:17.148 [main] INFO org.apache.jmeter.save.SaveService - Using SaveService properties file encoding UTF-8 18:56:17.156 [main] WARN org.apache.jmeter.save.SaveService - Can't register a converter: org.apache.jmeter.protocol.http.util.HTTPResultConverter java.lang.ClassNotFoundException: org.apache.jmeter.protocol.http.util.HTTPResultConverter at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at org.apache.jmeter.save.SaveService.registerConverter(SaveService.java:285) at org.apache.jmeter.save.SaveService.registerConverter(SaveService.java:260) at org.apache.jmeter.save.SaveService.initProps(SaveService.java:246) at org.apache.jmeter.save.SaveService.(SaveService.java:165) at com.solitera.automation.controller.JMeterFromExistingJMX.main(JMeterFromExistingJMX.java:75) 18:56:17.157 [main] INFO org.apache.jmeter.save.SaveService - Using SaveService properties version 5.0 18:56:17.175 [main] WARN org.apache.jmeter.save.SaveService - Can't register a converter: org.apache.jmeter.protocol.http.sampler.HTTPSamplerBaseConverter java.lang.ClassNotFoundException: org.apache.jmeter.protocol.http.sampler.HTTPSamplerBaseConverter at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at org.apache.jmeter.save.SaveService.registerConverter(SaveService.java:285) at org.apache.jmeter.save.SaveService.registerConverter(SaveService.java:260) at org.apache.jmeter.save.SaveService.initProps(SaveService.java:246) at org.apache.jmeter.save.SaveService.(SaveService.java:165) at com.solitera.automation.controller.JMeterFromExistingJMX.main(JMeterFromExistingJMX.java:75) 18:56:17.181 [main] INFO org.apache.jmeter.save.SaveService - Loading file: D:\apache-jmeter-5.1.1\extras\slt_autoMa_Test.jmx Exception in thread "main" java.lang.IllegalArgumentException: Problem loading XML from:'D:\apache-jmeter-5.1.1\extras\slt_autoMa_Test.jmx'. Cause: CannotResolveClassException: org.apache.jmeter.protocol.http.control.HeaderManager
Detail: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.save.ScriptWrapper converter-type : org.apache.jmeter.save.ScriptWrapperConverter path : /jmeterTestPlan/hashTree/hashTree/HeaderManager line number : 14 version : 5.2.1 ------------------------------- at org.apache.jmeter.save.SaveService.readTree(SaveService.java:459) at org.apache.jmeter.save.SaveService.loadTree(SaveService.java:432) at com.solitera.automation.controller.JMeterFromExistingJMX.main(JMeterFromExistingJMX.java:82) Caused by: 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.save.ScriptWrapper converter-type : org.apache.jmeter.save.ScriptWrapperConverter path : /jmeterTestPlan/hashTree/hashTree/HeaderManager line number : 14 version : 5.2.1 ------------------------------- at org.apache.jmeter.save.ScriptWrapperConverter.createConversionException(ScriptWrapperConverter.java:102) at org.apache.jmeter.save.ScriptWrapperConverter.unmarshal(ScriptWrapperConverter.java:96) at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:72) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134) at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32) at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1487) at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1467) at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1338) at org.apache.jmeter.save.SaveService.readTree(SaveService.java:449) ... 2 more Caused by: com.thoughtworks.xstream.converters.ConversionException: ---- Debugging information ---- cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException cause-message : org.apache.jmeter.protocol.http.control.HeaderManager 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/HeaderManager line number
: 14 ------------------------------- at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:77) at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:72) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readBareItem(AbstractCollectionConverter.java:132) at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:117) at org.apache.jmeter.save.converters.HashTreeConverter.unmarshal(HashTreeConverter.java:67) at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:72) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) at org.apache.jmeter.save.ScriptWrapperConverter.unmarshal(ScriptWrapperConverter.java:94) ... 12 more Caused by: com.thoughtworks.xstream.mapper.CannotResolveClassException: org.apache.jmeter.protocol.http.control.HeaderManager at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:81) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125) at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:55) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125) at com.thoughtworks.xstream.mapper.PackageAliasingMapper.realClass(PackageAliasingMapper.java:88) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125) at com.thoughtworks.xstream.mapper.ClassAliasingMapper.realClass(ClassAliasingMapper.java:79) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125) at com.thoughtworks.xstream.mapper.ArrayMapper.realClass(ArrayMapper.java:74) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125) at com.thoughtworks.xstream.mapper.SecurityMapper.realClass(SecurityMapper.java:71) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125) at org.apache.jmeter.save.SaveService$XStreamWrapper$1.realClass(SaveService.java:98) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125) at com.thoughtworks.xstream.mapper.CachingMapper.realClass(CachingMapper.java:47) at com.thoughtworks.xstream.core.util.HierarchicalStreams.readClassType(HierarchicalStreams.java:29) at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readBareItem(AbstractCollectionConverter.java:131) at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:117) at org.apache.jmeter.save.converters.HashTreeConverter.unmarshal(HashTreeConverter.java:67) at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) ... 23 more
pom.xml file
<!-- https://mvnrepository.com/artifact/org.apache.jmeter/ApacheJMeter_core --> <dependency> <groupId>org.apache.jmeter</groupId> <artifactId>ApacheJMeter_core</artifactId> <version>5.2.1</version> </dependency> <!-- https://mvnrepository.com/artifact/com.thoughtworks.xstream/xstream --> <dependency> <groupId>com.thoughtworks.xstream</groupId> <artifactId>xstream</artifactId> <version>1.4.11.1</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId> <version>4.4</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>com.lazerycode.jmeter</groupId> <artifactId>jmeter-maven-plugin</artifactId> <version>2.9.0</version> <executions> <execution> <id>jmeter-tests</id> <goals> <goal>jmeter</goal> </goals> </execution> </executions> <configuration> <overrideRootLogLevel>debug</overrideRootLogLevel> <propertiesUser> <jmeter.save.saveservice.output_format>xml</jmeter.save.saveservice.output_format> </propertiesUser> <testResultsTimestamp>false</testResultsTimestamp> <ignoreResultFailures>true</ignoreResultFailures> </configuration> </plugin> <!-- <plugin> <groupId>com.lazerycode.jmeter</groupId> <artifactId>jmeter-analysis-maven-plugin</artifactId> <version>1.0.4</version> <executions> <execution> <goals> <goal>analyze</goal> </goals> <phase>verify</phase> </execution> </executions> <configuration> source file that contains jmeter result data. Needs to be XML format or a GZIPed XML format <source>D:\Ecllipse_project_workspace2\slt_automation\target\jmeter\results\*</source> directory where to store analysis report files. At least a file "summary.txt" will be stored here. <targetDirectory>D:\Ecllipse_project_workspace2\slt_automation\target\jmeter\reports</targetDirectory> <logsDirectory>D:\Ecllipse_project_workspace2\slt_automation\target\jmeter\logs</logsDirectory> <processAllFilesFound>true</processAllFilesFound> </configuration> </plugin> --> <plugin> <groupId>com.lazerycode.jmeter</groupId> <artifactId>jmeter-analysis-maven-plugin</artifactId> <version>1.0.4</version> <executions> <execution> <goals> <goal>analyze</goal> </goals> <phase>verify</phase> </execution> </executions> <configuration> <!-- source file that contains jmeter result data. Needs to be XML format or a GZIPed XML format --> <source>${project.build.directory}/jmeter/results/*</source> <!-- directory where to store analysis report files. At least a file "summary.txt" will be stored here. --> <targetDirectory>${project.build.directory}/jmeter/reports</targetDirectory> <processAllFilesFound>true</processAllFilesFound> </configuration> </plugin> <plugin> <groupId>de.codecentric</groupId> <artifactId>jmeter-graph-maven-plugin</artifactId> <version>0.1.0</version> <configuration> <inputFile>${project.build.directory}/jmeter/results/slt_autoMa_Test.csv</inputFile> <graphs> <graph> <pluginType>ResponseTimesOverTime</pluginType> <width>800</width> <height>600</height> <outputFile>${project.build.directory}/jmeter/results/slt_autoMa_Test.png</outputFile> </graph> </graphs> </configuration> </plugin> </plugins> </build>