jmeter - generate various interface automation html reports

1. Realize the purpose

There are many tools and frameworks for interface automation, and the most commonly encountered implementation tool is jmeter;

Simple interface, lightweight installation and configuration, perfect functions, and low learning cost make jmeter the first choice of many people;

Especially for students with weak code foundation, it is more suitable to use this tool to realize interface automation, and it is also very convenient to do interface and performance testing;

For automation, there is one that is essential, the test report, the test report that can be provided externally. This article will talk about jmeter's implementation of interface automation test report

Provide solutions, currently provide four solutions to achieve, each has its own advantages and disadvantages, it is recommended to choose the solution that suits the project requirements.

2. Realize the effect

Next, let's talk about the html report effects that can be achieved by the four schemes

1. The HTML report that comes with jmter

insert image description here
performance test report

2. jmeter+ant report optimization

insert image description here

3. Execute the jmeter tool in batches

insert image description here

4. jmeter+allure generates a test report

insert image description here

3. Implementation plan

1. The HTML report that comes with jmeter

  1. Interface automation HTML
    (1) The implementation method is to call the biud file through ant.
    The first is ant installation and environment variable configuration: https://blog.csdn.net/tangsl666/article/details/79431037
    [Note]: Check first Take a look at the local JDK version, it is recommended to download ant1.10 if it is above 1.8, and it is recommended to download ant1.9 if it is below 1.8
    insert image description here

    (2) Copy the ant-jmeter-1.1.1.jar in the apache-jmeter-5.3\extras directory to the apache-ant-1.9.16\lib directory
    insert image description here

    (3) Create a build.xml file to modify the build content as follows:

<?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="F:\20220425\apache-jmeter-5.3\extras" />  
    <!-- 需要改成自己本地的 Jmeter 目录-->    
    <property name="jmeter.home" value="F:\20220425\apache-jmeter-5.3" />  
    <!-- jmeter生成jtl格式的结果报告的路径-->   
    <property name="jmeter.result.jtl.dir" value="F:\20220425\jmeterAnt\jtl" />  
    <!-- jmeter生成html格式的结果报告的路径-->  
    <property name="jmeter.result.html.dir" value="F:\20220425\jmeterAnt\html" />  
    <!-- Name of test (without .jmx) -->  
    <property name="test" value="Test"/>  
    <!-- 生成的报告的前缀-->    
    <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}">  
             <!-- 声明要运行的脚本。"*.jmx"指包含此目录下的所有jmeter脚本-->  
            <testplans dir="F:\20220425\jmeterAnt" includes="*.jmx" /> 
			<property name="jmeter.save.saveservice.output_format" value="xml"/>			
        </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>

(4) Put the modified build file in the ant directory, and then enter cmd in the ant directory file input box to enter the cmd command
Execute the command: ant, you can get the html report in the specified path
insert image description here

  1. Performance test report
    【win】+R Open the CMD window, enter the command to generate the HTML test report
    cmd command: jmeter -n -t script file path -l 11.jtl -e -o html
    jmetre: declare that the jmeter tool is called for execution
    -n : Execute JMeter in non-GUI mode
    -t: Execute the location of the test file
    -l: Specify the saved file for generating test results, such as: jtl, csv, xml, txt, etc. This file must not exist in the specified path
    -e: after the test, generate a test report
    -o: specify the storage location of the test report [the folder does not exist or is empty]
    Example: jemter -n -t E:\11. jmx -l E:\11.jtl -e -o html
    insert image description here

2. jmeter+ant optimization test report

Similar to the first step of jmeter's built-in html generation, ant executes the buid script

But you need to modify the build.xml file

<?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="F:\20220425\apache-jmeter-5.3\extras" />  
    <!-- 需要改成自己本地的 Jmeter 目录-->    
    <property name="jmeter.home" value="F:\20220425\apache-jmeter-5.3" />  
    <!-- jmeter生成jtl格式的结果报告的路径-->   
    <property name="jmeter.result.jtl.dir" value="F:\20220425\jmeterAnt\jtl" />  
    <!-- jmeter生成html格式的结果报告的路径-->  
    <property name="jmeter.result.html.dir" value="F:\20220425\jmeterAnt\html" />  
    <!-- Name of test (without .jmx) -->  
    <property name="test" value="Test"/>  
    <!-- 生成的报告的前缀-->    
    <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}">  
             <!-- 声明要运行的脚本。"*.jmx"指包含此目录下的所有jmeter脚本-->  
            <testplans dir="F:\20220425\jmeterAnt" includes="*.jmx" /> 
			<property name="jmeter.save.saveservice.output_format" value="xml"/>			
        </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.shanhe.me.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>

The jmeter.properties file in the bin directory of jmeter

jmeter.save.saveservice.output_format=xml
#jmeter.save.saveservice.output_format=xml   使用ant 命令时候打开这个,其他使用csv格式

# The below properties are true when field should be saved; false otherwise
#
# assertion_results_failure_message only affects CSV output
#jmeter.save.saveservice.assertion_results_failure_message=true
#
# legitimate values: none, first, all
#jmeter.save.saveservice.assertion_results=all
#
jmeter.save.saveservice.data_type=true
jmeter.save.saveservice.label=true
jmeter.save.saveservice.response_code=true
# response_data is not currently supported for CSV output
jmeter.save.saveservice.response_data=true
# Save ResponseData for failed samples
jmeter.save.saveservice.response_data.on_error=false
jmeter.save.saveservice.response_message=true
jmeter.save.saveservice.successful=true
jmeter.save.saveservice.thread_name=true
jmeter.save.saveservice.time=true
jmeter.save.saveservice.subresults=true
jmeter.save.saveservice.assertions=true
jmeter.save.saveservice.latency=true
# Only available with HttpClient4
jmeter.save.saveservice.connect_time=true
jmeter.save.saveservice.samplerData=true
jmeter.save.saveservice.responseHeaders=true
jmeter.save.saveservice.requestHeaders=true
jmeter.save.saveservice.encoding=true
jmeter.save.saveservice.bytes=true
# Only available with HttpClient4
#jmeter.save.saveservice.sent_bytes=true
jmeter.save.saveservice.url=true
jmeter.save.saveservice.filename=true
jmeter.save.saveservice.hostname=true
jmeter.save.saveservice.thread_counts=true
jmeter.save.saveservice.sample_count=true
jmeter.save.saveservice.idle_time=true

Finally, ant can call the build file. I won’t introduce it in detail here, you can see the link below for details

[Remarks]: For details, please refer to: https://blog.csdn.net/qq_32828053/article/details/124687407?spm=1001.2014.3001.5501

3. Use jmeter script batch execution tool to generate

Use the BAT tool to load and execute jmeter scripts in batches
BAT extraction path:
Link: https://pan.baidu.com/s/15HiGu6Ay-0d9Gy3Mj7gTOg
Extraction code: po6f

Instructions for use:
(1) After decompressing the file, click BAT.exe and select the installation path of jmeter
insert image description here

(2) Place the script to be executed in the BAT V2.0.4.0\TestCase\demo\sample directory (you can also create a new directory under testcase)
insert image description here

(3) BTA Select Project – “Quick Create: Create the ini file that currently executes the jmeter script
insert image description here
(4) Import the ini file and click to execute the script, and then automatically generate and open the test report
Project –> Open: Select the ini file just generated
insert image description here
insert image description here

4. jmeter+allure generates a test report

First, execute the jmeter script to generate the execution result file *.xml

Then parse the xml file by pytest

Add the allure tag to the parsed file

Finally, execute to generate allure report

【Remarks】For details, please refer to:

4. Remaining issues

Guess you like

Origin blog.csdn.net/qq_32828053/article/details/124682663