Recently in the use of JMeter write scripts to test, eventually wrote a lot of scripts, and then, just think, so many scripts, I can not one of the manual to point Ah, there is no way to run the JMeter script in bulk?
This time, naturally think of the Almighty ant, hope it can have a corresponding JMeter task.
Ah, ah, check a bit, there is really, cool crooked ah.
Here's a quick explanation, if you use:
① first, in order to be able to use JMeter task in Ant, the "Ant-jmeter-1.1.1.jar" jar package must be placed in Ant's classpath. This jar package is located in the Extras directory under the JMeter installation directory.
PS: You can copy this jar directly to the Lib directory in the ant installation directory.
② Writing scripts
Ant Code
- <?xml version="1.0" encoding="UTF-8"?>
- <project name="ant-jmeter-test" default="all" basedir="." >
- <tstamp>
- <format property= "Time" pattern="yyyymmddhhmm"/>
- </tstamp>
- <!--need to change to their local Jmeter directory--
- <property name="jmeter.home" value="F:\xxxxx\Jmeter"/>
- <!--jmeter Generate JTL Format Results report path--
- <property name="Jmeter.result.jtl.dir" value="F:\xxxxx\resultLog\jtl"/>
- <!--JMeter generates a path to the results report in HTML format--
- <property name="Jmeter.result.html.dir" value="F:\xxxxx\resultLog\html"/>
- < prefix for reports generated by!--
- <property name="ReportName" value="Testreport"/>
- <property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${reportname}${time}.jtl"/>
- <property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${reportname}${time}.html"/ >
- <target name="All" >
- <antcall target="test"/>
- <antcall target="Report"/>
- </target>
- <target name="Test" >
- <taskdef name="JMeter" classname="Org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
- <jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlname}" >
- <!--declare the script to run. "*.jmx" means all JMeter scripts that contain this directory--
- <testplans dir="D:\test_case_path" includes="*.jmx"/>
- </jmeter>
- </target>
- <target name="Report" >
- <xslt in="${jmeter.result.jtlname}"
- out="${jmeter.result.htmlname}"
- style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl"/>
- <!--because when the report is generated, the associated pictures are not copied to the target directory, so you need to manually copy--
- <copy todir="${jmeter.result.html.dir}" >
- <fileset dir="${jmeter.home}/extras" >
- <include name="Collapse.png"/>
- <include name="Expand.png"/>
- </fileset>
- </copy>
- </target>
- </project>
③ generated results reports such as
④ Here is a question I encountered in the process of using: The following error has been reported when executing the task that generated the report last:
Transformerexception, Content is not allowed in Prolog.
Later on the Ant-jmeter official online found the reason:
Java code
- Note:as of JMeter 1.9rc2 (?), the default results output format is now CSV. It must is changed to XML in order to use the XSLT task to create the HTML report:
So we need to modify a configuration of JMeter
Java code
- Jmeter.save.saveservice.output_format=xml
And then you can generate the report normally.
Attached: Ant-jmeter official website: http://www.programmerplanet.org/projects/jmeter-ant-task/
Go: Batch execute jmeter script via Ant and Generate report (attached: Generate report times "Content is not allowed in Prolog" solution for this error)