jmeter+ant+jenkins interface automation test

Setting up Jmeter environment

Set up a java environment first
1. Official Web http://www.oracle.com/technetwork/java/javase/downloads/index.html Download
2. Setting system variables,
The variable name is JAVA_HOME=C:\Program Files\Java\jdk1.8.0_131 (Installed Path Directory)
Set Path variable,%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin
Variable name CLASSPATH, variable value.;% JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar
3. Verify that the installation was successful, enter cmd for win+r to see the java version of java -version

Setting up a jmeter environment
1. Official Web https://jmeter.apache.org/ Download
2. Setting system variables,
Variable name: JMETER_HOME=E:\apache-jmeter-5.1.1 (Installed path directory)
Set Path variable,%JMETER_HOME%\bin
Variable name CLASSPATH,%JMETER_ HOME%\lib\ext\ApacheJMeter_ Core.jar;% JMETER_ HOME%\lib\jorphan.jar;% JMETER_ HOME%\lib/logkit-2.0.jar;
3. Verify that the installation was successful, enter cmd for win+r and jmeter for jmeter

Set up Ant environment

1. Official Web http://ant.apache.org/bindownload.cgi Download (select -bin)
2. Setting system variables,
Variable name: ANT_HOME=E:\application\apache-ant-1.10.9 (Installed path directory)
Set Path variable, C:/ apache-ant-1.10.1/bin
Variable name CLASSPATH, C:/apache-ant-1.10.1/lib
3. Verify that the installation was successful, enter cmd for win+r and ant for ant

Install jenkins

1. Official Web https://www.jenkins.io/ Download
2. Installation (recommended default download plugin), Address (default): 127.0.0.1:8080

Verify that Ant runs the script successfully

1. Modify the configuration of jmeter.properties file in Jmeter's bin directory: jmeter.save.saveservice.output_format=xml
The purpose is to format the Jmeter report output file as xml, remember to remove the previous #

2. Configuration file:
1. Copy the ant-jmeter-1.1.1.jar file in the jmeter extras directory to the lib folder in the ant installation directory
2. There is a build.xml document under the jmeter's extras file that is placed in the folder to be executed (Ant runs the JMeter script from this file (key documents, need to be configured correctly)

<?xml version="1.0" encoding="UTF-8"?>  
  
<project name="ant-jmeter-test" default="run" basedir=".">  
      
    <tstamp>  
        <format property="time" pattern="yyyyMMddhhmm" />  
    </tstamp>  
    <property name="basedirectory" value="D:\MyDrivers\apache-jmeter-5.1.1\extras" />  
    <!-- Need to change to your own local Jmeter Catalog-->    
    <property name="jmeter.home" value="D:\MyDrivers\apache-jmeter-5.1.1" />  
    <!-- jmeter generate jtl Path to result report in format-->   
    <property name="jmeter.result.jtl.dir" value="D:\MyDrivers\project\jtl" />  
    <!-- jmeter generate html Path to result report in format-->  
    <property name="jmeter.result.html.dir" value="D:\MyDrivers\project\html" />  
    <!-- Name of test (without .jmx) -->  
    <property name="test" value="Test"/>  
    <!-- Prefix for generated reports-->    
    <property name="ReportName" value="TestReport" />  
    <property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${time}.jtl" />  
    <property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${time}.html" />  
      
    <path id="xslt.classpath">  
        <fileset dir="${jmeter.home}/lib" includes="xalan*.jar"/>  
        <fileset dir="${jmeter.home}/lib" includes="serializer*.jar"/>  
    </path>  
      
    <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}">  
             <!-- Declare the script to run."*.jmx"Refers to all that contain this directory jmeter Script-->  
            <testplans dir="D:\MyDrivers\project\jmeterjmt" includes="*.jmx" />  
        </jmeter>  
    </target>  
          
    <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="${report.datestamp}"/>  
        </xslt>  
        <copy todir="${jmeter.result.html.dir}">  
            <fileset dir="${jmeter.home}/extras">  
                <include name="collapse.png" />  
                <include name="expand.png" />  
            </fileset>  
        </copy>  
    </target>  
      
</project>

3. Create a new folder project under the jmeter installation directory, a new folder report under project, a new jtl and html folder under report, and the role of html and jtl folders:
html folder: used to save html result reports
jtl folder: test script used to save jmeter
jmeterjmt folder: scripts to be executed
Shift+right mouse button, open powerShell window, enter ant (or ant run), execute xml file script, verify whether script ant can execute successfully

4. Open Jenkins, in Settings-Global Tool Configuration, add Ant (downloaded without checking download, take the directory address where ant is installed, ==If not found, you need to install the ant plug-in)

5. Create a new task, add the build.xml address built by ant, click Save

6. Start building

Tags: Java jenkins Testing

Posted on Fri, 03 Dec 2021 18:11:26 -0500 by Kryllster