jmeter actual combat: jmeter+ant+jenkins lightweight interface automation test (windows)

There is no need for cattle knives to kill pigs. There is no difference between cattle and tall tools. Every tool has its own reason for existence; The key is to see if it can be used, how to use it, and whether it is used in the right place. Tools to install:
jdk1.8
Jmeter4.0
ant1.9 (ANT)
jenkins2.1 (Jenkins)

1. Environment configuration

1. windows installation jdk: https://blog.csdn.net/qq_40468470/article/details/116940914
2. Windows an jmeter installation: you can download a jmeter without installation. However, the following environment variables need to be configured:
Add two attributes to the system variable
① JMETER_ Home = D: \ Apache jmetes \ apache-jmeter-4.0 (the path saved by JMeter)
② CLASSPATH=%JMETER_HOME%\lib\ext\ApacheJMeter_core.jar; %JMETER_HOME%\lib\jorphan.jar;
(this copy is OK) if the classpath variable exists, add a variable directly after it. If not, create a new one. Pay attention to each variable; separate
(3) add;% after the system variable path JMETER_HOME%\bin note that this is a system variable

3. Installing tomcat for windows: https://blog.csdn.net/qq_40468470/article/details/117824576
4. windows install ant: https://blog.csdn.net/qq_40468470/article/details/117825203
5. Windows configuration jenkins: https://blog.csdn.net/qq_40468470/article/details/117825441
All the above environments have been installed and checked ok.

Here, you can also use ant to run jmeter scripts, but it doesn't realize automation-----------
Steps:
1. Create a new testcases folder at any location (Note: it is not recommended to have a Chinese directory in the location path of the folder)
2. Create a new cases folder under the testcases folder to store the thread group (at this time, you can put a correct thread group in it for the next demonstration)

3. Create a new report folder under the testcases folder, and then create a jtl folder to store log reports and an html folder to store operation reports.

4. Add Ant-jmeter-1.1.1. In the extras subdirectory of the directory where JMeter is located Copy the jar to the lib subdirectory of the Ant directory.

5. Modify bin / jmeter. In jmeter directory Properties, find
jmeter.save.saveservice.output_format, remove the comments and set it to xml.

Open with notepad + +

6. Create a new build in the testcases folder XML file, enter the following contents (I will comment on all the places that need to be modified later + important Oh, a total of five places):

<?xml version="1.0" encoding="utf-8"?>
<project name="jmeter_test" default="all" basedir=".">
    <tstamp>
        <format property="time" pattern="yyyyMMddhhmm" />
    </tstamp>
    <!-- Need to change to your own local Jmeter catalogue-->
    <property name="jmeter.home" value="E:\ouyang_study\Interface test\one\apache-jmeter-5.2" />#important
    <!-- jmeter generate jtl Path to the result report in format-->
    <property name="jmeter.result.jtl.dir" value="E:\ouyang_study\Interface test\one\apache-jmeter-5.2\result\jtl" />#important
    <!-- jmeter generate html Path to the result report in format-->
    <property name="jmeter.result.html.dir" value="E:\ouyang_study\Interface test\one\apache-jmeter-5.2\result\html" />#important
    <!-- Prefix of the generated report -->
    <property name="ReportName" value="TestReport_whweia" />
    <!-- Generate various files-->
	<!--<property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}.jtl" />-->
	<property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}${time}.jtl" />
    <!-- <property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}.html" />-->
	<property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}${time}.html" />

    <!-- Mailbox to receive test report -->
<!--    <property name="mail_to" value="whweia@vip.qq.com" />-->
    <!-- Computer address -->
<!--    <property name="ComputerName" value="xiaoqiang" />-->

	<!-- Solution not shown Min/Max The problem of counting time. Put the following two at the same time jar file copy reach ant of lib In the bag-->
	<path id="xslt.classpath">
	<fileset dir="${jmeter.home}/lib" includes="xalan-2.7.1.jar"/>
	<fileset dir="${jmeter.home}/lib" includes="serializer-2.7.1.jar"/>
	</path>

    <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"It refers to including all under this directory jmeter script -->
            <testplans dir="D:\testcases\cases" includes="*.jmx" />#Important your file path
        </jmeter>
    </target>
	<!-- jmeter-results-detail-report_21.xsl   or    jmeter.results.shanhe.me.xsl-->
    <target name="report">
		<!-- Solve the problem of not displaying time-->
		<tstamp> <format property="report.datestamp" pattern="yyyy/MM/dd HH:mm" /></tstamp>
        <xslt in="${jmeter.result.jtlName}" out="${jmeter.result.htmlName}" style="${jmeter.home}/extras/jmeter.results.shanhe.me.xsl" >#important
		<param name="dateReport" expression="${report.datestamp}"/>
		</xslt>
        <!-- Because the relevant pictures will not be copied to the target directory when the report is generated above, it needs to be copied manually -->
        <copy todir="${jmeter.result.html.dir}">
            <fileset dir="${jmeter.home}/extras">
                <include name="collapse.png" />
                <include name="expand.png" />
            </fileset>
        </copy>
    </target>
</project>



The fifth important content is JMeter results detail report_ 21.xsl:

7. Check the results, so you can run ant now
So how does it work:
Run ant under the folder you just created locally

Enter cmd enter

Seeing success is ok

Open the report here:

8. So what if you don't want to run manually or automatically.. Just use jenkins-------
Previously, I entered in the address bar of the browser: http://127.0.0.1:8080/jenkins Or http://localhost:8080/jenkins We have entered the initial interface of Jenkins. After loading, the following scenario will appear:

Sometimes there is an address in windows that cannot be reached by cmd. You can find it yourself in the folder. The password is stored in the last initialAdminPassword file.
After filling in the account information, enter the following scenario:

Select the recommended plug-ins to install.
Set the account and password yourself, and remember. After logging in, it looks like this.

9. New freestyle project

After confirmation:


Note:

Click Save to continue configuring the test report
If the recommended plug-in is not installed, you need to download a plug-in Public HTML reports here
System management - management plug-ins - optional plug-ins enter HTML Publisher for query and installation


Next, continue to configure the report:

Select the report generation address (the previous build.xml already has a generation location, which cannot be omitted):

The following is the key point (setting the automatic execution time):

Contents of the schedule:

Build every 5 minutes
H/5 * * * *
Build every two hours
H H/2 * * *
Build it regularly at 12 noon every day
H 12 * * *
Build it regularly at 18 p.m. every day
H 18 * * *
Every 10 minutes in the first half hour of each hour
H(0-29)/10 * * * *
Every two hours and 45 minutes from 9 a.m:45 Start at 3 p.m. every day:45 end
45 9-16/2 * * 1-5
 Every two hours, from 9 a.m. to 5 p.m. every working day(Maybe 10 a.m:38,12 pm:38,2 pm:38,4 pm:38)
H H(9-16)/2 * * 1-5

After clicking save:

To view the construction:


If you have filled in the content of post build operation, you can view the report in the following location:

If not, you can view the report in your new testcases\report\html Directory:


Knowledge supplement:
Operations in my views:

Generated report style:

Keywords: jenkins jmeter

Added by pellky on Wed, 02 Feb 2022 20:44:14 +0200