jmeter + ant automated interface testing environment configuration

Front: Install jdk 1.8 or more

 First, install jemeter

Download: http://jmeter.apache.org/download_jmeter.cgi

1.1 decompression jmeter, in a directory, such as D: \ Program Files \ apache-jmeter-3.1

1.2 Jmeter environment variable configuration:

  1.2.1 New JEMTER_HOME:

    Fill value to D: \ Program Files \ apache-jmeter-3.1

  1.2.2 Editing CLASSPATH:

     添加 %JMETER_HOME%\lib\ext\ApacheJMeter_core.jar;%JMETER_HOME%\lib\jorphan.jar;%JMETER_HOME%\lib\logkit-2.0.jar

1.3 test whether the configuration:

  dos command line input jmeter can start jmeter That success

 

 

Second, install Ant:

Ant Download:  http://ant.apache.org/bindownload.cgi

2.1 extract the ant, in a directory, for example: D: \ Program Files \ apache-ant-1.10.6-bin \ apache-ant-1.10.6

2.2 Configuration Environment Variables

  2.2.1 Add ANT_HOME, configured value D: \ Program Files \ apache-ant-1.10.6-bin \ apache-ant-1.10.6;

  2.2.2 Editing path, add% ANT_HOME% / bin

2.3 test whether the successful installation configuration

C:\Users\pc>ant -version

Apache Ant(TM) version 1.10.6 compiled on May 2 2019

Third, the. \ Apache-jmeter-3.1 \ extras \ copy ant-jmeter-1.1.1.jar file to the ant installation directory lib subdirectory

Fourth, the configuration file build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="ant-jmeter-test" default="run" basedir=".">
      <tstamp>
        <format property="time" pattern="_yyyy_MMdd_HHmmss" />
    </tstamp>
    <!-- 需要改成自己本地的 Jmeter 目录-->  
    <property name="jmeter.home" value="D:\Program Files\apache-jmeter-3.1" />
    </>= "Interface test"value= "report.title"nameProperty
    <! - path jmeter format generated jtl reported results ->  
    < Property name = "jmeter.result.jtl.dir" value = "D: \ Program Files \ Apache-jmeter-3.1 \ Test \ JmeterAutoTest \ PC \ resultlog \ JTL "  /> 
    ! <- path jmeter generated html format results reported -> 
    < Property name =" jmeter.result.html.dir " value =" D: \ Program Files \ Apache-jmeter-3.1 \ the Test \ JmeterAutoTest \ PC \ resultlog \ HTML "  /> 
    < Property name =" the Detail " value =" _ the Detail "  /> 
    <-! generate reports prefix ->   
    <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="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" > 
            <! - - script statement you want to run "* .jmx" refers jmeter contains all the scripts in this directory -> 
            < testplans dir = "D: \ Program Files \-jmeter the Apache-3.1 \ the Test \ JmeterAutoTest \ PC \ script" includes = ".jmx *"  /> 

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

    <path id="xslt.classpath">
        <fileset dir="${jmeter.home}/lib" includes="xalan*.jar"/>
        <fileset 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="showData" expression="${show-data}"/>
              <param name="titleReport" expression="${report.title}"/>
              <param name="dateReport" expression="${report.datestamp}"/> 
       </xslt>
                <!--Since when generating reports above the associated picture will not be copied to the target directory together, therefore, you need to manually copy ->  
        < Copy todir = "$ {} jmeter.result.html.dir" > 
            < fileset the dir = " jmeter.home} {$ / Extras " > 
                < the include name =" collapse.png "  /> 
                < the include name =" expand.png "  /> 
            </ fileset > 
        </ Copy > 
    </ target > 

</ Project >

The next five .dos command line cd to the path where the build.xml, type ant execution, the script will automatically execute jmeter

Guess you like

Origin www.cnblogs.com/zhuomou/p/11404297.html