Ant + Jmeter the batch script

 

1. Download and install Ant

(1) Download

Address: https://ant.apache.org/bindownload.cgi

(2) extracting, environment configuration:

ANT_HOME: Ant unzip the file path; as: D: \ software \ apache-ant-1.9.14-bin \ apache-ant-1.9.14

path: bin directory path ANT; if: D: \ software \ apache-ant-1.9.14-bin \ apache-ant-1.9.14 \ bin

classpath: lib Ant directory path; if: D: \ software \ apache-ant-1.9.14-bin \ apache-ant-1.9.14 \ lib

(3) Check if the installation was successful

cmd into the Ant installation location \ bin directory

ant -version

If errors are reported, suggesting not find tools.jar, in addition to xxxx path;

Workaround: tools.jar at xxxx path copied to the Java installation directory \ lib:

如:D:\software\jdk-8u211-windows-x64\java\lib

2.Jmter + ant script batch execution.

Prerequisite: already installed Jmeter, and there are multiple scripts, Jmeter installation not repeat them.

(1) The Jmeter installation path \ ant-jmeter-1.1.1.jar under extras copied to the install directory ant \ lib folder.

(2) modify the installation path Jmeter \ extras under the build.xml configuration file as follows:

<?xml version="1.0" encoding="UTF-8"?>

<project name="ant-jmeter-test" default="run" basedir=".">
    <tstamp>
        <format property="time" pattern="yyyyMMddhhmm" />
    </tstamp>
    <!-- 需要改成自己本地的jmeter目录-->
    <property name="jmeter.home" value="D:\software\Jmeter\apache-jmeter-5.1.1" />
    <!- nameProperty<->path jtl reported results generated jmeter format
    = "jmeter.result.jtl.dir" value = "D: \ Files \ Practice \ the Jmeter \ load_scripts \ JTL"  /> 
    ! <- result report generated html format jmeter path -> 
    < Property name = " jmeter.result.html.dir " value =" D: \ Files \ Practice \ the Jmeter \ load_scripts \ HTML "  /> 
    ! <- " prefix generated reports -> 
    < Property name = "the ReportName" value = "the TestReport "  /> 
    < Property name =" jmeter.result.jtlName " value =" $ {jmeter.result.jtl.dir} / {the ReportName $ $}} {Time .jtl "  /> 
    <property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}${time}.html" />

    <target name="run">
        <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}">
             <!--To run the script declaration of "* .jmx" refers jmeter contains all the scripts in this directory -> 
            < testplans dir = "D: \ Files \ Practice \ Jmeter \ load_scripts" Includes =. "* JMX"  /> 

           < Property name = "jmeter.save.saveservice.output_format" value = "XML" /> 

        </ JMeter > 
    </ target > 
    < path ID = "xslt.classpath" > 
            < fileset the dir = "$ {jmeter.home} / lib" Includes = "Xalan * .jar" /> 
            < fileset the dir = "${jmeter.home}/lib" includes="serializer*.jar"/>
    </path>

    <target name="report">
        <tstamp>
                <format property="report.datestamp" pattern="yyyy/MM/dd HH:mm" />
        </tstamp>
        <xslt
            classpathref="xslt.classpath"
            force="true"
            in="${jmeter.result.jtlName}"
            out="${jmeter.result.htmlName}"
            style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl">
            <param name= "dateReport" expression The = "$ {report.datestamp}" /> 
        </ XSLT > 
        <-! picture resources needed to copy reports to the target directory -> 
        < Copy todir = "$ {jmeter.result.html. } the dir " > 
            < fileset the dir =" $ {} jmeter.home / Extras " > 
                < the include name =" collapse.png "  /> 
                < the include name =" expand.png "  /> 
            </ fileset > 
        </ Copy > 
    < / target > 
</project>

(3) and a plurality of Jmeter build.xml file to be executed in the same folder, while modifying path of the corresponding code stored build.xml

 

(4) cmd into the build.xml directory, enter ant, to automatically execute the script.

(5) compiled successfully, you can view reports in the corresponding directory, open the HTML file.

detail-report.xsl file in the installation directory Jmeter extras folder.

 

Guess you like

Origin www.cnblogs.com/Bella-gan123/p/11110733.html