jmeter修改报告模板

JMeter has built-in ant integration, which allows us to run JMeter from command line. The result of running from command line is a JTL output file. This file is actually an XML file, and can be converted to an HTML file for better readability using an XSL stylesheet. HTML files converted using the stylesheet provided here will look similar to

Fig. 1.  An example HTML file converted from a JTL file in IE9.

Installation:

  1. Edit extras/build.xml in the JMeter distribution, locate
    <!-- Force suitable defaults -->
    <property name="jmeter.save.saveservice.output_format" value="xml"/>
    <property name="jmeter.save.saveservice.assertion_results" value="all"/>
    <property name="jmeter.save.saveservice.bytes" value="true"/>
    <property name="file_format.testlog" value="${format}"/>
    <property name="jmeter.save.saveservice.response_data.on_error" value="${funcMode}"/>

    and add as much information as you want, such as

    <!-- Force suitable defaults -->
    <property name="jmeter.save.saveservice.response_data" value="true"/>
    <property name="jmeter.save.saveservice.samplerData" value="true"/>
    <property name="jmeter.save.saveservice.responseHeaders" value="true"/>
    <property name="jmeter.save.saveservice.requestHeaders" value="true"/>
    <property name="jmeter.save.saveservice.encoding" value="true"/>
    <property name="jmeter.save.saveservice.url" value="true"/>
    <property name="jmeter.save.saveservice.filename" value="true"/>
    <property name="jmeter.save.saveservice.hostname" value="true"/>
    <property name="jmeter.save.saveservice.thread_counts" value="true"/>
    <property name="jmeter.save.saveservice.sample_count" value="true"/>
    <property name="jmeter.save.saveservice.idle_time" value="true"/>
    <property name="jmeter.save.saveservice.output_format" value="xml"/>
    <property name="jmeter.save.saveservice.assertion_results" value="all"/>
    <property name="jmeter.save.saveservice.bytes" value="true"/>
    <property name="file_format.testlog" value="${format}"/>
    <property name="jmeter.save.saveservice.response_data.on_error" value="${funcMode}"/>

    so that what you see in the JMeter GUI will be shown in the HTML file. The property names were found inbin/jmeter.properties.

  2. Locate in extras/build.xml again for
    <target name="report" depends="_message_xalan">
      <xslt
        classpathref="xslt.classpath"
        force="true"
          in="${testpath}/${test}.jtl"
          out="${testpath}/${test}.html"
          style="${basedir}/jmeter-results-detail-report${style_version}.xsl">
        <param name="showData" expression="${show-data}"/>
      </xslt>
    </target>

    Change the style attribute to look like

    <target name="report" depends="_message_xalan">
      <xslt
        classpathref="xslt.classpath"
        force="true"
          in="${testpath}/${test}.jtl"
          out="${testpath}/${test}.html"
          style="${basedir}/jmeter-results-shanhe-me.xsl">
        <param name="showData" expression="${show-data}"/>
      </xslt>
    </target>
  3. Download jmeter-results-shanhe-me.xsl by following the links at the bottom of the page, and save the file toextras/jmeter-results-shanhe-me.xsl.
  4. From the Command Prompt, change the current working directory to the extras folder, e.g., "cd C:\jakarta-jmeter-2.4\extras", and execute "ant". This will run Test.jmx and get Test.html.
    Fig. 2.  Execute ant from the Command Prompt.
  5. You can also specify the path and the file name of the jmx file, e.g., you can run "ant -Dtest=Test -Dtestpath=C:\jakarta-jmeter-2.4\extras" to execute the same Test.jmx in the extras folder.
    Fig. 3.  Execute ant with the path and the file name specified from the Command Prompt.

The output HTML file is compatible with Ie8+/Opera/Firefox/Safari/Chrome.




修改后的build文件

<?xml version="1.0"?>
<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at
    
       http://www.apache.org/licenses/LICENSE-2.0
    
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<project name="ant-jmeter" default="all">
    <description>

        Sample build file for use with ant-jmeter.jar
        See http://www.programmerplanet.org/pages/projects/jmeter-ant-task.php

    To run a test and create the output report:
        ant -Dtest=script

    To run a test only:
        ant -Dtest=script run

    To run report on existing test output
        ant -Dtest=script report

    The "script" parameter is the name of the script without the .jmx suffix.

    Additional options:
        -Dshow-data=y - include response data in Failure Details
        -Dtestpath=xyz - path to test file(s) (default user.dir).
                         N.B. Ant interprets relative paths against the build file
        -Djmeter.home=.. - path to JMeter home directory (defaults to parent of this build file)
        -Dreport.title="My Report" - title for html report (default is 'Load Test Results')

        Deprecated:
        -Dformat=2.0 - use version 2.0 JTL files rather than 2.1

    </description>
    
    <property name="testpath" value="${user.dir}"/>
    <property name="jmeter.home" value="${basedir}/.."/>
    <property name="report.title" value="Load Test Results"/>
    
    <!-- Name of test (without .jmx) -->
    <property name="test" value="Test"/>
    
    <!-- Should report include response data for failures? -->
    <property name="show-data" value="n"/>

    <property name="format" value="2.1"/>
    
    <condition property="style_version" value="">
        <equals arg1="${format}" arg2="2.0"/>
    </condition>

    <condition property="style_version" value="_21">
        <equals arg1="${format}" arg2="2.1"/>
    </condition>

    <condition property="funcMode">
        <equals arg1="${show-data}" arg2="y"/>
    </condition>
    
    <condition property="funcMode" value="false">
      <not>
        <equals arg1="${show-data}" arg2="y&#

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值