jmeter+ant interface automation test framework

(Note: the installation and configuration of jdk and jmeter are not described here)

Ant Download

1. You need to configure environment variables first:

ANT_HOME   D:\apache-ant


Path %ANT_HOME%\bin


After configuring the ant environment variable, verify whether the environment variable is effective under dos:

ant -version



2. Copy ant-jmeter-1.1.1.jar under extras under JMeter directory to lib directory under ant directory.

3. Modify the bin\ configuration file of JMeter and find the configuration item: ,

Replace with:




4. Configure the script that ant calls jmeter to run and convert the generated jtl format report to html format. Create a new build.xml in the path where the script is stored.

The configuration information is as follows:


<?xml version="1.0" encoding="UTF-8"?>
<project name="ant-jmeter-test" default="run" basedir=".">
		<format property="time" pattern="_yyyy_MMdd_HHmmss"/>
	<!-- Configure local jmeter route -->
	<property name="jmeter.home" value="D:\apache-jmeter-5.4.1" />
	<!-- to configure jmeter Execute script path -->
	<property name="jmeter.script.dir" value="D:\apache-jmeter-5.4.1\testScript" />
	<!-- Configure report name -->
	<property name="report.title" value="Interface automation test" />
	<!-- to configure jmeter Generated after running jtl Path of format report -->
	<property name="jmeter.result.jtl.dir" value="D:\apache-jmeter-5.4.1\testScript" />
	<!-- to configure jmeter generate html Path to format report -->
	<property name="jmeter.result.html.dir" value="D:\apache-jmeter-5.4.1\testScript" />
	<!--Description of the configuration Report-->
	<property name="detail" value="_detail" />
	<!--Configure the file name for generating the report-->
	<property name="ReportName" value="ApiTestreport" />
	<property name="ReportNameDetail" value="ApiTestreportDetail" />
	<!--to configure jmeter Generated after execution jtl Path of report storage-->
	<property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}${time}.jtl" />
	<!--to configure jtl Report format converted to html After that, there are two different report names because I have configured two template reports  -->
	<property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}${time}.html" />
	<property name="jmeter.result.detail_htmlName" value="${jmeter.result.html.dir}/${ReportNameDetail}${time}.html" />

	<target name="run">
		<antcall target="test" />
		<antcall target="report" />

	<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 ,Refers to all in this directory jmx script-->
			<testplans dir="${jmeter.script.dir}" includes="*.jmx" />
			<property name="" value="xml" />

	<path id="xslt.classpath">
		<fileset dir="${jmeter.home}/lib" includes="xalan*.jar" />
		<fileset dir="${jmeter.home}/lib" includes="serializer*.jar" />	

	<target name="report">
			<format property="report.datestemp" pattern="yyyy/MM/dd HH:mm" />
		<!-- call jmeter The built-in generation template is displayed in the extras You can find it next time -->
		<xslt classpathref="xslt.classpath" 
			  <param name="titleReport" expression="${report.title}" />
			  <param name="dateReport" expression="${report.datestemp}" />

		<!-- Call a set of templates written by others. The information displayed is more detailed. You need to download the template yourself and put it in the extras Call under directory -->
		<xslt classpathref="xslt.classpath" 
			  <param name="dateReport" expression="${report.datestemp}" />

		<!-- When generating the report, the relevant pictures will not be copied to the target directory, so they need to be copied manually -->
		<copy todir="${jmeter.result.html.dir}">
			<fileset dir="${jmeter.home}/extras">
				<include name="collapse.png" />
				<include name="expand.png" />


Note: if the file is not downloaded and stored in extras, you need to comment out the following configuration:




  If has been downloaded and placed in the extras directory, you need to configure in the / bin directory to see the effect.

You need to change all the following configurations to: true

After all the above are configured, switch to the newly created build.xml directory under the dos command and execute:

ant -f build.xml

If you see BUILD SUCCESSFUL, it indicates successful execution and correct configuration



After execution, the generated html format report of jmeter is as follows



After execution, another report template written by others is generated, as follows:



Problems encountered: during configuration, the paths of some directories are written incorrectly or the ant command is not executed in the build.xml directory, resulting in the following problems:

Ant: the 'ant' entry cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Check the spelling of the name. If you include a path, make sure the path is correct,

Then try again.

Location line: 1 character: 1

+ ant -f build.xml

+ ~~~

    + CategoryInfo          : ObjectNotFound: (ant:String) [], CommandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException



1. Check whether the path in the configuration is correct. You can copy the path of the configuration item and paste it directly in the address bar in windows Resource Management to see whether it enters the corresponding directory.

2. Check whether the configured parameters are written correctly, especially the xml has strong hierarchical verification. Note whether the parent and child labels are closed correctly

3. In dos environment, switch to the path where build.xml is located, and then execute ant -f build.xml, or execute the specified file path, such as ant -f d:\testScript\build.xml


Keywords: jmeter

Added by aerodromoi on Thu, 25 Nov 2021 00:17:31 +0200