转载自南风_real博客园:http://www.cnblogs.com/jaychang/p/5881525.html

但是最近在查阅相关资料时,发现基本都是重复一篇文章Jmeter使用笔记之html报告扩展(一),而且有很多看不明白的地方,于是根据自己需求,在报告中修改了一些,现在整理分享出来。

优化后效果图:

1. 邮件发送html报告有中文时,显示乱码:

修改encoding为“GBK”

<xsl:output method="html" indent="yes" encoding="GBK" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" />

2. Summary中的只标红Failures数:

  • 屏蔽Summary中class属性

            <!--
    <xsl:attribute name="class">
    <xsl:choose>
    <xsl:when test="$allFailureCount &gt; 0">Failure</xsl:when>
    </xsl:choose>
    </xsl:attribute>
    -->
  • 修改allFailureCount

            <td align="center">
    <xsl:value-of select="$allSuccessCount" />
    </td>
    <xsl:choose>
    <xsl:when test="$allFailureCount &gt; 0">
    <td align="center" style="font-weight:bold">
    <font color="red">
    <xsl:value-of select="$allFailureCount" />
    </font>
    </td>
    </xsl:when>
    <xsl:otherwise>
    <td align="center">
    <xsl:value-of select="$allFailureCount" />
    </td>
    </xsl:otherwise>
    </xsl:choose>

3. Pages页面按Average Time倒序排序:

在Pagelist模板中for-each下添加

<xsl:for-each select="/testResults/*[not(@lb = preceding::*/@lb)]"  >
<!-- 按平均时间排序 -->
<xsl:sort select="sum(../*[@lb = current()/@lb]/@t) div count(../*[@lb = current()/@lb])" data-type="number" order="descending"/>

4. 接口Average Time超过2s标黄显示:

  • 添加LongTime css
                .Failure {
font-weight:bold; color:red;
}
.LongTime {
font-weight:bold; color:#ff9900;
}
  • Pagelist 模块中针对错误和超长时间接口标色显示
            <tr valign="top">
<xsl:choose>
<!-- 失败用例标红显示 -->
<xsl:when test="$failureCount &gt; 0">
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="$failureCount &gt; 0">Failure</xsl:when>
</xsl:choose>
</xsl:attribute>
</xsl:when>
<!-- 平均时间超过2s,标色显示 -->
<xsl:when test="$averageTime &gt; 2000">
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="$averageTime &gt; 2000">LongTime</xsl:when>
</xsl:choose>
</xsl:attribute>
</xsl:when>
</xsl:choose>

5. 添加90% Line和QPS:

  • 添加90 %lineTime模板
<xsl:template name="max">
<xsl:param name="nodes" select="/.." />
<xsl:choose>
<xsl:when test="not($nodes)">NaN</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$nodes">
<xsl:sort data-type="number" order="descending" />
<xsl:if test="position() = 1">
<xsl:value-of select="number(.)" />
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template> <!-- 90% line time -->
<xsl:template name="lineTime">
<xsl:param name="nodes" select="/.." />
<xsl:choose>
<xsl:when test="not($nodes)">NaN</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$nodes">
<xsl:sort data-type="number" />
<!-- last() 返回当前上下文中的最后一个节点位置数 -->
<!-- ceiling(number) 返回大于number的最小整数 -->
<!-- floor(number) 返回不大于number的最大整数 -->
<!-- position() 返回当前节点位置的数字 -->
<!-- number(object) 使对象转换成数字 -->
<xsl:choose>
<!-- 当只有一个节点时,向上取整 -->
<xsl:when test="last() = 1">
<xsl:if test="position() = ceiling(last()*0.9)">
<xsl:value-of select="number(.)" />
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:if test="position() = floor(last()*0.9)">
<xsl:value-of select="number(.)" />
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
  • 添加display-qps模板
 

<xsl:template name="display-qps">
  <xsl:param name="value" />
  <xsl:value-of select="format-number($value,'0.000 /s')" />
</xsl:template>

  • Sunmary中添加标题
        <tr valign="top">
<th># Samples</th>
<th>Success</th>
<th>Failures</th>
<th>Success Rate</th>
<th>Average Time</th>
<th>Min Time</th>
<th>Max Time</th>
<th>90% Line</th>
<th>QPS</th>
</tr>
  • Summary中添加allLineTime和qps变量
            <xsl:variable name="allMaxTime">
<xsl:call-template name="max">
<xsl:with-param name="nodes" select="/testResults/*/@t" />
</xsl:call-template>
</xsl:variable>
<!-- New add 90% line -->
<xsl:variable name="allLineTime">
<xsl:call-template name="lineTime">
<xsl:with-param name="nodes" select="/testResults/*/@t" />
</xsl:call-template>
</xsl:variable>
<!-- 将毫秒转换成秒 -->
<xsl:variable name="qps" select="$allCount * 1000 div $allTotalTime"/>
  • Summary中调用allLineTime和qps变量
            <td align="center">
<xsl:call-template name="display-time">
<xsl:with-param name="value" select="$allMaxTime" />
</xsl:call-template>
</td>
<td align="center">
<xsl:call-template name="display-time">
<xsl:with-param name="value" select="$allLineTime" />
</xsl:call-template>
</td>
<td align="center">
<xsl:call-template name="display-qps">
<xsl:with-param name="value" select="$qps" />
</xsl:call-template>
  • pagelist中添加标题
<xsl:template name="pagelist">
<h2>Pages</h2>
<table align="center" class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
<tr valign="top">
<th>URL</th>
<th># Samples</th>
<th>Success</th>
<th>Failures</th>
<th>Success Rate</th>
<th>Average Time</th>
<th>Min Time</th>
<th>Max Time</th>
<th>90% Line</th>
<th>QPS</th>
<th></th>
</tr>
  • pagelist中添加allLineTime和qps变量
            <xsl:variable name="maxTime">
<xsl:call-template name="max">
<xsl:with-param name="nodes" select="../*[@lb = current()/@lb]/@t" />
</xsl:call-template>
</xsl:variable>
<!-- new add 90% line time -->
<xsl:variable name="nintyTime">
<xsl:call-template name="lineTime">
<xsl:with-param name="nodes" select="../*[@lb = current()/@lb]/@t" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="qpsTime" select="$count * 1000 div $totalTime"/>
  • pagelist中调用allLineTime和qps变量
                <td align="center">
<xsl:call-template name="display-time">
<xsl:with-param name="value" select="$maxTime" />
</xsl:call-template>
</td>
<!-- Page页面添加90% LineTime -->
<td align="center">
<xsl:call-template name="display-time">
<xsl:with-param name="value" select="$nintyTime" />
</xsl:call-template>
</td>
<td align="center">
<xsl:call-template name="display-qps">
<xsl:with-param name="value" select="$qpsTime" />
</xsl:call-template>
</td>

6.Failure Detail模块显示Response Data:

  • 设置showData为‘y’
<!-- Defined parameters (overrideable) -->
<xsl:param name="showData" select="'y'"/>
<xsl:param name="titleReport" select="'Interface Test Results'"/>
<xsl:param name="dateReport" select="'date not defined'"/>
  • 替换内容
                <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
<tr valign="top">
<th align="center">Response</th>
<th align="center">Failure Message</th>
<xsl:if test="$showData = 'y'">
<th align="left">Response Data</th>
</xsl:if>
</tr> <xsl:for-each select="/testResults/*[@lb = current()/@lb][attribute::s='false']">
<tr>
<td><xsl:value-of select="@rc | @rs" /> - <xsl:value-of select="@rm" /></td>
<td><xsl:value-of select="assertionResult/failureMessage" /></td>
<xsl:if test="$showData = 'y'">
<td><xsl:value-of select="responseData" /></td>
</xsl:if>
</tr>
</xsl:for-each>

7.添加Host

<xsl:template name="pageHeader">
<h1><xsl:value-of select="$titleReport" /></h1>
<table width="100%">
<tr>
<!-- 获取requestHeader数据 -->
<xsl:variable name="URL" select="/testResults/httpSample/requestHeader" />
<!-- 从获取的URL中截取数据,第二代表起始位置,第三位代表长度 -->
<xsl:variable name="newURL" select="substring($URL, 94, 40)" />
<!-- 已换行符来截取,before代表换行符之前的数据 -->
<xsl:variable name="remaining" select="substring-before($newURL, ' ')" />
<td align="left">Date report: <xsl:value-of select="$dateReport" /></td>
<td align="center">Host: <xsl:value-of select="$remaining" /></td>
<td align="right"><a href="./TestLog.html">测试日志</a></td>
</tr>
</table>

Jmeter Html 报告优化的更多相关文章

  1. Jmeter默认报告优化

    一.本文目的: 之前写了两篇文章搭建持续集成接口测试平台(Jenkins+Ant+Jmeter)和ANT批量执行Jmeter脚本,功能实现上都没有什么问题,但是最后生成的报告有一点小问题,虽然不影响使 ...

  2. jmeter(十五)Jmeter默认报告优化

    一.本文目的: 之前写了两篇文章搭建持续集成接口测试平台(Jenkins+Ant+Jmeter)和ANT批量执行Jmeter脚本,功能实现上都没有什么问题,但是最后生成的报告有一点小问题,虽然不影响使 ...

  3. Jmeter报告优化之New XSL stylesheet

    Jmeter默认的报告展示的信息比较少,如果出错了,不是很方便定位问题.由Jmeter默认报告优化这篇文章可知,其实由.jtl格式转换为.html格式的报告过程中,style文件起了很关键的作用.下面 ...

  4. 转Jmeter报告优化之New XSL stylesheet

    Jmeter默认的报告展示的信息比较少,如果出错了,不是很方便定位问题.由Jmeter默认报告优化这篇文章可知,其实由.jtl格式转换为.html格式的报告过程中,style文件起了很关键的作用.下面 ...

  5. jmeter+ant+jenkins+mac报告优化

    一.在上篇博客中生成的报告有两个问题: 1.date not defined 2.Min Time和Max Time显示成了NaN 二.Jmeter+Ant报告生成原理: 在解决问题之前,让我们先弄清 ...

  6. jmeter+ant+jenkins+mac报告优化(一):解决Min Time和Max Time显示NaN

    一.在上篇博客中生成的报告有两个问题: 1.date not defined 2.Min Time和Max Time显示成了NaN 二.Jmeter+Ant报告生成原理: 1.在Jmeter的extr ...

  7. jmeter报告优化---展示详细信息

    参考文档:https://www.cnblogs.com/puresoul/p/5049433.html 楼上博主写的还是很详细,在报告优化这块,但是在操作中也走了一些弯路,我改动了两个点才成功,根据 ...

  8. 你真的了JMeter解聚合报告么?

    1.背景 大家在使用JMeter进行性能测试时,聚合报告(Aggregate Report)可以说是必用的监听器,但是你真的了解聚合报告么? 2.目的 本次笔者跟大家聊聊聚合报告(Aggregate ...

  9. 【jmeter】测试报告优化<一>

    具体问题如下: 1.Date report这里的时间没有正确显示出来 2.Summary里的字段Min Time和Max Time显示的是NaN,没有显示正确的时间. 本文主要解决上述两个问题,具体报 ...

随机推荐

  1. C# 常用加密处理

    AES using System; using System.Security.Cryptography; using System.Text; namespace Common { public c ...

  2. myBatis 参数配置

    关于参数的类型 有四种类型: http://www.07net01.com/zhishi/402787.html 以上链接有所介绍,四种类型有:单个参数.多个参数.Map封装参数.List封装IN 如 ...

  3. EDIUS和VEGAS哪个更好用

    随着数字化电视系统发展的步伐日趋加快,计算机技术逐步渗透到广播电视的各个领域,非线性编辑系统在广播电视行业内占据越来越重要的地位,而且正向多样化 发展.因此,非线性编辑技术的操作应用对于编辑人员有着非 ...

  4. risc与cisc

    RISC(精简指令集计算机)和CISC(复杂指令集计算机)是当前CPU的两种架构.它们的区别在于不同的CPU设计理念和方法. 早期的CPU全部是CISC架构,它的设计目的是要用最少的机器语言指令来完成 ...

  5. tagName和nodeName的区别

      首先介绍DOM里常见的三种节点类型(总共有12种,如docment):元素节点,属性节点以及文本节点,例如<h2 class="title">head</h2 ...

  6. 使用bind(this)的情况

    1.setInterval().setTimeout()的回调函数,一定要加.bind(this)方法. 原因是:在setInterval()中定义的回调函数,是在同步代码执行完后,随着事件触发来异步 ...

  7. Redis 高可用性解决方案(Sentinel)

    Sentinel是Redis的高可用性解决方案: 由一个或多个Sentinel实例组成的Sentinel系统可以监视任意多个主服务器,以及所有从服务器,并在被监视的主服务器进入下线状态时,自动将下线主 ...

  8. Kettle使用jndi mssqlserver

    kettle可以使用jdbc的方式设置job或者tansform的数据库连接,但是,同时它也支持JNDI方式连接数据库,后者更加方便,只需要配置一份配置文件就可以了,不用每个DBConnection都 ...

  9. Intellij Idea 12 生成serialVersionUID的方法

    默认情况下Intellij IDEA是关闭了继承了java.io.Serializable的类生成serialVersionUID的警告.如果需要ide提示生成serialVersionUID,那么需 ...

  10. android ANR

    下面有两篇关于Android ANR的文章,感觉不错,分享一下! [Android实例] [Sundy系列]网上绝无仅有的Log分析教程及例子!android ANRhttp://blog.csdn. ...