ant+jmeter 报告优化

时间:2022-12-11 13:53:45

环境基础:ant+jmeter+java +jmeter脚本

1.将 JMeter的extras目录中ant-jmeter-1.1.1.jar包拷贝至ant安装目录下的lib目录中

2.修改JMeter的bin目录下jmeter.properties文件的配置:jmeter.save.saveservice.output_format=xml

      ant+jmeter 报告优化

3.复制F:\study\apache-jmeter-3.1\apache-jmeter-3.1\extras下build.xml到自己需要放报告的目录下,进行配置

4.复制F:\study\apache-jmeter-3.1\apache-jmeter-3.1\extras下collapse.png、expand.png到需要放的报告的目录

5.在build.xml目录下 运行 ant 

我配置的build如下

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <!--
 3    Licensed to the Apache Software Foundation (ASF) under one or more
 4    contributor license agreements.  See the NOTICE file distributed with
 5    this work for additional information regarding copyright ownership.
 6    The ASF licenses this file to You under the Apache License, Version 2.0
 7    (the "License"); you may not use this file except in compliance with
 8    the License.  You may obtain a copy of the License at
 9     
10        http://www.apache.org/licenses/LICENSE-2.0
11     
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17 -->
18 <project name="ant-jmeter" default="run" basedir=".">    
19     
20     <!-- 需要改成自己本地的 Jmeter 目录--> 
21     <property name="jmeter.home" value="F:\study\apache-jmeter-3.1\apache-jmeter-3.1"/>
22     <property name="report.title" value="cltest"/>
23     <!-- jmeter生成jtl、html格式的结果报告的路径-->
24     <property name="jmeter.result.dir" value="E:\code\jmeterReport\resultReport"/>
25     <!-- 生成的报告的前缀-->  
26     <property name="ReportName" value="TestReport" />
27     <property name="jmeter.result.jtlName" value="${jmeter.result.dir}/${ReportName}.jtl" />
28     <property name="jmeter.result.htmlName" value="${jmeter.result.dir}/${ReportName}.html"/>
29     
30     <target name="run">
31         <antcall target="test" />
32         <antcall target="report" />
33     </target>   
34 
35 
36    <target name="test">
37          <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
38          <jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}">
39              <!-- 声明要运行的脚本。"*.jmx"指包含此目录下的所有jmeter脚本-->
40             <testplans dir="E:\code\jmeterReport" includes="*.jmx" />
41             <property name="jmeter.save.saveservice.output_format" value="xml"/>
42          </jmeter>
43     </target>
44      <!-- html报告中时间显示为NAN,原因是ant中缺失了两个lib库  xalan-2.7.2.jar和serializer-2.7.2.jar ,将这两个库拷贝到ant的lib目录下,或者在这里增加如下代码均可解决-->
45     <path id="xslt.classpath">
46         <fileset dir="${jmeter.home}/lib" includes="xalan*.jar" />
47         <fileset dir="${jmeter.home}/lib" includes="serializer*.jar"/>
48     </path>
49         
50     <target name="report">
51         <tstamp> 
52            <format property="report.datestamp" pattern="yyyy/MM/dd HH:mm" />
53         </tstamp>
54         <xslt 
55             classpathref="xslt.classpath"
56             force="true"
57             in="${jmeter.result.jtlName}"
58                out="${jmeter.result.htmlName}"
59                style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl" >
60             <param name="dateReport" expression="${report.datestamp}"/>
61         </xslt>
62          
63           <!-- 因为上面生成报告的时候,不会将相关的图片也一起拷贝至目标目录,所以,需要手动拷贝 --> 
64         <copy todir="${jmeter.result.html.dir}">
65             <fileset dir="${jmeter.home}/extras">
66                  <include name="collapse.png" />
67                  <include name="expand.png" />
68             </fileset>
69         </copy>
70     </target>
71  </project>

 

遇到的问题:

1.the <jmeter> type doesn't support nested text data("  ")

ant+jmeter 报告优化

解决办法:

1)

ant+jmeter 报告优化

后面发现没有注释掉其实也是可以的,其实还是编码问题 与2)解决一致

ant+jmeter 报告优化

 

 2)编码格式  Notepad++使用 编码》以ANSI与UTF无BOM格式编码查看,会发现有多余的文字,删除掉即可

ant+jmeter 报告优化

 

ant+jmeter 报告优化

 

 2.

ant+jmeter 报告优化

解决办法:

ant+jmeter 报告优化

3.生成的报告部分显示不出来  

1)、Date report这里的时间没有正确显示出来

2)、Summary里的字段Min Time和Max Time显示的是NaN,没有显示正确的时间

3)、pages最后一列图片显示不对

ant+jmeter 报告优化

 解决办法:

1)http://www.cnblogs.com/puresoul/p/5053035.html

2)http://www.cnblogs.com/puresoul/p/5053035.html

3)图片位置不对

ant+jmeter 报告优化