51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 1849|回复: 2
打印 上一主题 下一主题

Jmeter Html 报告优化

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2018-2-26 14:52:25 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1. 邮件发送html报告有中文时,显示乱码:

修改encoding为“GBK”
  1. <xsl:output method="html" indent="yes" encoding="GBK" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" />
复制代码
2. Summary中的只标红Failures数:
屏蔽Summary中class属性
  1. <!-- <xsl:attribute name="class"> <xsl:choose> <xsl:when test="$allFailureCount > 0">Failure</xsl:when> </xsl:choose> </xsl:attribute> -->
复制代码
修改allFailureCount
  1. <td align="center"> <xsl:value-of select="$allSuccessCount" /> </td> <xsl:choose> <xsl:when test="$allFailureCount > 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>
复制代码
Pages页面按Average Time倒序排序:

在Pagelist模板中for-each下添加
  1. <xsl:for-each select="/testResults/*[not(@lb = preceding::*/@lb)]"   >
  2.             <!-- 按平均时间排序 -->
  3.             <xsl:sort select="sum(../*[@lb = current()/@lb]/@t) div count(../*[@lb = current()/@lb])" data-type="number" order="descending"/>
复制代码
. 接口Average Time超过2s标黄显示:

添加LongTime css
  1. .Failure {
  2.     font-weight:bold; color:red;
  3. }
  4. .LongTime {
  5.     font-weight:bold; color:#ff9900;
  6. }
复制代码
Pagelist 模块中针对错误和超长时间接口标色显示
  1. <tr valign="top">
  2.     <xsl:choose>
  3.         <!-- 失败用例标红显示 -->
  4.         <xsl:when test="$failureCount > 0">
  5.             <xsl:attribute name="class">
  6.                 <xsl:choose>
  7.                     <xsl:when test="$failureCount > 0">Failure</xsl:when>
  8.                 </xsl:choose>
  9.             </xsl:attribute>
  10.         </xsl:when>
  11.         <!-- 平均时间超过2s,标色显示 -->
  12.         <xsl:when test="$averageTime > 2000">
  13.             <xsl:attribute name="class">
  14.                 <xsl:choose>
  15.                     <xsl:when test="$averageTime > 2000">LongTime</xsl:when>
  16.                 </xsl:choose>
  17.             </xsl:attribute>
  18.         </xsl:when>
  19.     </xsl:choose>
复制代码
添加90% Line和QPS:

添加90 %lineTime模板
  1. <xsl:template name="max">
  2.     <xsl:param name="nodes" select="/.." />
  3.     <xsl:choose>
  4.         <xsl:when test="not($nodes)">NaN</xsl:when>
  5.         <xsl:otherwise>
  6.             <xsl:for-each select="$nodes">
  7.                 <xsl:sort data-type="number" order="descending" />
  8.                 <xsl:if test="position() = 1">
  9.                     <xsl:value-of select="number(.)" />
  10.                 </xsl:if>
  11.             </xsl:for-each>
  12.         </xsl:otherwise>
  13.     </xsl:choose>
  14. </xsl:template>

  15. <!-- 90% line time -->
  16. <xsl:template name="lineTime">
  17.     <xsl:param name="nodes" select="/.." />
  18.     <xsl:choose>
  19.         <xsl:when test="not($nodes)">NaN</xsl:when>
  20.         <xsl:otherwise>
  21.             <xsl:for-each select="$nodes">
  22.                 <xsl:sort data-type="number" />
  23.                 <!-- last() 返回当前上下文中的最后一个节点位置数 -->
  24.                 <!-- ceiling(number) 返回大于number的最小整数 -->
  25.                 <!-- floor(number) 返回不大于number的最大整数 -->
  26.                 <!-- position() 返回当前节点位置的数字 -->
  27.                 <!-- number(object) 使对象转换成数字 -->
  28.                 <xsl:choose>
  29.                     <!-- 当只有一个节点时,向上取整 -->
  30.                     <xsl:when test="last() = 1">
  31.                         <xsl:if test="position() = ceiling(last()*0.9)">
  32.                             <xsl:value-of select="number(.)" />
  33.                         </xsl:if>
  34.                     </xsl:when>
  35.                     <xsl:otherwise>
  36.                         <xsl:if test="position() = floor(last()*0.9)">
  37.                             <xsl:value-of select="number(.)" />
  38.                         </xsl:if>
  39.                       </xsl:otherwise>
  40.                 </xsl:choose>
  41.             </xsl:for-each>
  42.         </xsl:otherwise>
  43.     </xsl:choose>
  44. </xsl:template>

  45. Sunmary中添加标题
  46. <tr valign="top">
  47.     <th># Samples</th>
  48.     <th>Success</th>
  49.     <th>Failures</th>
  50.     <th>Success Rate</th>
  51.     <th>Average Time</th>
  52.     <th>Min Time</th>
  53.     <th>Max Time</th>
  54.     <th>90% Line</th>
  55.     <th>QPS</th>
  56. </tr>
  57. Summary中添加allLineTime和qps变量
  58. <xsl:variable name="allMaxTime">
  59.     <xsl:call-template name="max">
  60.         <xsl:with-param name="nodes" select="/testResults/*/@t" />
  61.     </xsl:call-template>
  62. </xsl:variable>
  63. <!-- New add 90% line -->
  64. <xsl:variable name="allLineTime">
  65.     <xsl:call-template name="lineTime">
  66.         <xsl:with-param name="nodes" select="/testResults/*/@t" />
  67.     </xsl:call-template>
  68. </xsl:variable>
  69. <!-- 将毫秒转换成秒 -->
  70. <xsl:variable name="qps" select="$allCount * 1000 div $allTotalTime"/>
  71. Summary中调用allLineTime和qps变量
  72. <td align="center">
  73.     <xsl:call-template name="display-time">
  74.         <xsl:with-param name="value" select="$allMaxTime" />
  75.     </xsl:call-template>
  76. </td>
  77. <td align="center">
  78.     <xsl:call-template name="display-time">
  79.         <xsl:with-param name="value" select="$allLineTime" />
  80.     </xsl:call-template>
  81. </td>
  82. <td align="center">
  83.     <xsl:call-template name="display-qps">
  84.         <xsl:with-param name="value" select="$qps" />
  85.     </xsl:call-template>
  86. pagelist中添加标题
  87. <xsl:template name="pagelist">
  88.     <h2>Pages</h2>
  89.     <table align="center" class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
  90.         <tr valign="top">
  91.             <th>URL</th>
  92.             <th># Samples</th>
  93.             <th>Success</th>
  94.             <th>Failures</th>
  95.             <th>Success Rate</th>
  96.             <th>Average Time</th>
  97.             <th>Min Time</th>
  98.             <th>Max Time</th>
  99.             <th>90% Line</th>
  100.             <th>QPS</th>
  101.             <th></th>
  102.         </tr>
  103. pagelist中添加allLineTime和qps变量
  104. <xsl:variable name="maxTime">
  105.     <xsl:call-template name="max">
  106.         <xsl:with-param name="nodes" select="../*[@lb = current()/@lb]/@t" />
  107.     </xsl:call-template>
  108. </xsl:variable>
  109. <!-- new add 90% line time -->
  110. <xsl:variable name="nintyTime">
  111.     <xsl:call-template name="lineTime">
  112.         <xsl:with-param name="nodes" select="../*[@lb = current()/@lb]/@t" />
  113.     </xsl:call-template>
  114. </xsl:variable>
  115. <xsl:variable name="qpsTime" select="$count * 1000 div $totalTime"/>
  116. pagelist中调用allLineTime和qps变量
  117. <td align="center">
  118.     <xsl:call-template name="display-time">
  119.         <xsl:with-param name="value" select="$maxTime" />
  120.     </xsl:call-template>
  121. </td>
  122. <!-- Page页面添加90% LineTime -->
  123. <td align="center">
  124.     <xsl:call-template name="display-time">
  125.         <xsl:with-param name="value" select="$nintyTime" />
  126.     </xsl:call-template>
  127. </td>
  128. <td align="center">
  129.     <xsl:call-template name="display-qps">
  130.         <xsl:with-param name="value" select="$qpsTime" />
  131.     </xsl:call-template>
  132. </td>
  133. 6.Failure Detail模块显示Response Data:

  134. 设置showData为‘y’
  135. <!-- Defined parameters (overrideable) -->
  136. <xsl:param    name="showData" select="'y'"/>
  137. <xsl:param    name="titleReport" select="'Interface Test Results'"/>
  138. <xsl:param    name="dateReport" select="'date not defined'"/>

  139. 替换内容
  140. <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
  141. <tr valign="top">
  142.     <th align="center">Response</th>
  143.     <th align="center">Failure Message</th>
  144.     <xsl:if test="$showData = 'y'">
  145.         <th align="left">Response Data</th>
  146.     </xsl:if>
  147. </tr>

  148. <xsl:for-each select="/testResults/*[@lb = current()/@lb][attribute::s='false']">
  149.     <tr>
  150.         <td><xsl:value-of select="@rc | @rs" /> - <xsl:value-of select="@rm" /></td>
  151.         <td><xsl:value-of select="assertionResult/failureMessage" /></td>
  152.         <xsl:if test="$showData = 'y'">
  153.             <td><xsl:value-of select="responseData" /></td>
  154.         </xsl:if>
  155.     </tr>
  156. </xsl:for-each>
  157. 7.添加Host

  158. <xsl:template name="pageHeader">
  159.     <h1><xsl:value-of select="$titleReport" /></h1>
  160.     <table width="100%">
  161.         <tr>
  162.             <!-- 获取requestHeader数据 -->
  163.             <xsl:variable name="URL" select="/testResults/httpSample/requestHeader" />
  164.             <!-- 从获取的URL中截取数据,第二代表起始位置,第三位代表长度 -->
  165.             <xsl:variable name="newURL" select="substring($URL, 94, 30)" />
  166.             <!-- 已换行符来截取,before代表换行符之前的数据 -->
  167.             <xsl:variable name="remaining" select="substring-before($newURL, '
  168. ')" />
  169.             <td align="left">Date report: <xsl:value-of select="$dateReport" /></td>
  170.             <td align="center">Host: <xsl:value-of select="$remaining" /></td>
  171.             <td align="right"><a href="./TestLog.html">测试日志</a></td>
  172.         </tr>
  173.     </table>
复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-5-12 16:03 , Processed in 0.069632 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表