Jmeter(二十九)Jmeter-Question之“Ant集成报告模板优化”

  也是在和朋友探讨的时候,发现一个问题,Jmeter在与Ant集成的时候,通常选用的模板是jmeter自带的两个样式表

  

  该自带的样式,节省了大家搭建框架的时间,不需要自己重新写样式,当然也相对简洁;

  做接口测试时,我们通常跑的接口有很多,其日志的也是相对比较大的,因此对于一些报错原因、响应报文想查看,便形成了一种障碍;自带的模板不带有查看响应报文的样式,因此需要一种能够直观查看一些类似成功率、失败率以及响应有误能够直接查看的样式模板。

  找到一份模板,是copy这位大师的模板。http://www.cnblogs.com/puresoul/p/4808416.html。

  样式源码Copy一份。

  

  1 <?xml version="1.0" encoding="GB2312"?>
  2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  3     <xsl:output method="html" indent="no" encoding="UTF-8" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" doctype-system="http://www.w3.org/TR/html4/loose.dtd"/>
  4     <xsl:strip-space elements="*"/>
  5 
  6 
  7     <xsl:template name="detail">
  8         <xsl:variable name="allFailureCount" select="count(/testResults/*[attribute::s='false'])" />
  9 
 10         <xsl:if test="$allFailureCount > 0">
 11             <h2>Failure Detail</h2>
 12 
 13             <xsl:for-each select="/testResults/*[not(@lb = preceding::*/@lb)]">
 14 
 15                 <xsl:variable name="failureCount" select="count(../*[@lb = current()/@lb][attribute::s='false'])" />
 16 
 17                 <xsl:if test="$failureCount > 0">
 18                     <h3><xsl:value-of select="@lb" /></h3>
 19 
 20                     <table align="center" class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
 21                     <tr valign="top">
 22                         <th>Response</th>
 23                         <th>Failure Message</th>
 24                     </tr>
 25                 
 26                     <xsl:for-each select="/testResults/*[@lb = current()/@lb][attribute::s='false']">
 27                         <tr>
 28                             <td><xsl:value-of select="@rc | @rs" /> - <xsl:value-of select="@rm" /></td>
 29                             <td><xsl:value-of select="assertionResult/failureMessage" /></td>
 30                         </tr>
 31                     </xsl:for-each>
 32                     
 33                     </table>
 34                 </xsl:if>
 35 
 36             </xsl:for-each>
 37         </xsl:if>
 38     </xsl:template>
 39 
 40     <xsl:template match="/testResults">
 41         <html lang="en">
 42         <head>
 43             <meta name="Author" content="shanhe.me"/>
 44             <title>JMeter Test Results</title>
 45             <style type="text/css"><![CDATA[
 46             
 47                 * { margin: 0; padding: 0 }
 48                 
 49                 table.details tr th{
 50                     color: #ffffff;
 51                     font-weight: bold;
 52                     text-align:center;
 53                     background:#2674a6;
 54                     line-height:2em;                    
 55                 }
 56                 
 57                 table.details tr:nth-child(odd){background:#FFFFFF;border:1px solid #CCC;line-height:2em;}
 58                 table.details tr:nth-child(even){background:#EDF3FE;border:1px solid #CCC;line-height:2em;}
 59                 table.details td{border:1px solid black;}
 60                 .Failure {
 61                     font-weight:bold; color:red;
 62                 }
 63                 html{ width: 100%; height: 100%; background: #b4b4b4; font-size: 12px }
 64                 body { width: 95%; height: 95%; margin: 0 auto; }
 65                 table { border: none; border-collapse: collapse; table-layout: fixed;word-wrap:break-word;word-break:break-all; }
 66                 #panel-wrap {position:relative;width: 100%;height: 100%;}
 67                 td { vertical-align: baseline; font-size: 12px }
 68     
 69                 #left-panel { position: absolute; left: 0; top: 0; bottom: 0; width: 30%; overflow: auto; background: #dee4ea }
 70                 #left-panel li.navigation { font-weight: bold; cursor: default; color: #9da8b2; line-height: 18px; background-position: 12px 5px; background-repeat: no-repeat; padding: 0 0 0 25px; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAICAYAAAArzdW1AAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sDEBQqGbO7BEcAAAAdaVRYdENvbW1lbnQAAAAAAENyZWF0ZWQgd2l0aCBHSU1QZC5lBwAAAKRJREFUGNN1zM0KgkAYheF3RvtXSsGyWhRNaILS7bdt11W0KgJvoPwZp0UlBPUtz3nOJw7Hk7necv5dOA2Qaazo2vZP0LEt9olCVtqQROufKNmuqBuBNAYW4QzXGX6B0bDPcjGnMQYJ8Cg12U59oSzaUJQa4IUAXMclDHwAAn/MxPMw765FZd2QRgopBWmsKCrdfhXnS/4ZYElBXdyxewN008Y8AephLAkqz613AAAAAElFTkSuQmCC) }
 71                 #left-panel li.success { color: #565b60 }
 72                 #left-panel li.failure { color: red }
 73                 #left-panel li { list-style: none; color: black; cursor: pointer }
 74                 #left-panel li.selected { background-repeat: repeat-x; color: white; background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAUCAYAAABMDlehAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sDEBQxLTs5O2gAAAAdaVRYdENvbW1lbnQAAAAAAENyZWF0ZWQgd2l0aCBHSU1QZC5lBwAAAEdJREFUCNc1y7ERgEAMA0GNUhIyGqM2uqKgtyWZhE9v53A/7/A6D7BkMDNgy2AroB2wHTCZv5UMOgFLG1bvd7XBckBlwCXjA5wMOF5iOX/MAAAAAElFTkSuQmCC) }
 75                 #left-panel div { line-height: 20px; background-position: 25px 3px; background-repeat: no-repeat; padding: 0 0 0 45px }
 76                 #left-panel div.success { background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAOCAYAAADwikbvAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sDEBULEEc6wzcAAAAdaVRYdENvbW1lbnQAAAAAAENyZWF0ZWQgd2l0aCBHSU1QZC5lBwAAAiNJREFUKM99kktIVGEYhp/jzJl08lI6logp2Y2EFkbtaqlFROsWrlq4ioJWQRs37VoUVItWkYEVRGSBlhleCpywDEWxTEuxcURTZ6YzxzP/5WshCOHUt36f93kXnyMi5Lsnb4clI4s4fhkXzp5w8mWcfHBvfEpUxVdCUUU6lUPNHuD86cYtBQX5GhPrM7hRg7GaSDRg2vuUd90WuOPVsOyqy6FFo2yOQHlU1S9z9dZT+S/8I7GCLlkAN4eyAf56mnT6Fy1HLnGuuYa++MS/4e74qMRqfXLaJ9BpfnsrLC0m2BYuoqwUbj/+274JD43OEqmexwvW8NUKXnaZtVSS1pNtAAyOvyC6v48HnUNb4Z7PH8UtTlIQWA5tb2RhYY7kz3l2FleytJYg/qWb8t2KZ/0PN+1hgI6uEUr2jpHKpGlquExVaS0VbjUZL7WxaqIXK6ADQ0n9GNfv9XCttWnD/O57t0TKFklnF3g5fJ/seoaa2D4O1x0F4PlgO9oIftbgFgYMfLgjACGqj0vlsddoUnj+Kt/mxunq72RP+UGqYjWMTA7R+b6dUCSEGEF5hoJQip6BaFs4HJtCyRrKs6wHCovDip/kys0WWpovMpOYBCtoT2N9B5uzWG0Zid8gnFrVFEQDtBaUrxEgXBimaEeER2/uIiK4roPOaMRYjBKsFly3fOO3G06dETGCWIsYjckprMphtEKMAQtgsMYi1mJMQHJ6xvkDKQoyphCzkl0AAAAASUVORK5CYII=) }
 77                 #left-panel div.failure { background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAOCAYAAADwikbvAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sDEBUJOEC5CU8AAAAdaVRYdENvbW1lbnQAAAAAAENyZWF0ZWQgd2l0aCBHSU1QZC5lBwAAAeVJREFUKM+NkDtok2EUhp8vl9ZLo/EyKI6KFgqCKC4OClrBWUQEcRRx1cGpk3WyInWrgoMZKkW8thYaEYQ0i7WC2ngrNDTERHJvkv/L/3//dxwc7F8jeOAsh/c973OOEhG61aPnaen7maXYt4MLZ4+pbppQt+F06jNH3QWOb8pxUs+SmJzjv83hxY8SVy3wNdtVneiHqe54IhLoB4/TUkyMyOrKj5yXoVtPZK02kLyYK7OnlqFWzgcCGtUC/YUJ3n5a/jd28tU7ORTN0myUA6Jms8bpWIa798elqzn1fokjThrpVBC3ETzNbYAuca59j/Hp+b/N869Tsk8tgVMCXQk+RlfQuk1/tMLMwzsSMCcm5zjhvoR2AdpF0GuwO4aqttS05ZSbZHhsBoAIwI83Cdkd/460XDAOG02d24MxvlR8dsUUh3f2UHaEtgdbWCHz4oZwcVCp66PP5FLhKjEc8DXaCMsNy8DYn/SnZ+L0hhWOb/F8yLs9fDtwk8j+VpqwrlC34PrgGEu2bhlYhZ1b8dncq3AMeBaUr/k6NUyk4ChKzu+N2hc6Bqody+WDG8g2fLatD7F3axjPgmvAtYJvIbouhhIRrl0ZktnkBGIt1gqeMXQ8D2MMiCIUCqFEsFhEQMSykCuqX0MzLAUJTzRsAAAAAElFTkSuQmCC) }
 78                 #left-panel div.detail { display: none }
 79                 #right-panel { position: absolute; right: 0; top: 0; bottom: 0; left: 30%; overflow: auto; background: white }
 80                 #right-panel .group { font-size: 12px; font-weight: bold; line-height: 16px; padding: 0 0 0 18px; counter-reset: assertion; background-repeat: repeat-x; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAQCAYAAADXnxW3AAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sDEBUkDq8pxjkAAAAdaVRYdENvbW1lbnQAAAAAAENyZWF0ZWQgd2l0aCBHSU1QZC5lBwAAADdJREFUCNdVxrERwDAMAzGK0v47eS6Z927SpMFBAAbkvSvnRk5+7K5cVfLMyN39bWakJAjA5xw9R94jN3tVhVEAAAAASUVORK5CYII=) }
 81                 #right-panel .zebra { background-repeat: repeat; padding: 0 0 0 18px; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAmCAYAAAAFvPEHAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sDEBYWFlNztEcAAAAdaVRYdENvbW1lbnQAAAAAAENyZWF0ZWQgd2l0aCBHSU1QZC5lBwAAABdJREFUCNdjYKAtePv5338mBgYGBpoQAGy1BAJlb/y6AAAAAElFTkSuQmCC) }
 82                 
 83                 #right-panel .data { line-height: 19px; }
 84                 #right-panel pre.data { white-space: pre }
 85                 #right-panel tbody.failure { color: red }
 86                 #right-panel td.key { min-width: 108px }
 87                 #right-panel td.delimiter { min-width: 18px }
 88                 #right-panel td.assertion:before { counter-increment: assertion; content: counter(assertion) ". " }
 89                 #right-panel td.assertion { color: black }
 90                 #right-panel .trail { border-top: 1px solid #b4b4b4 }
 91                 
 92             ]]></style>
 93             <script type="text/javascript"><![CDATA[
 94             
 95                 var onclick_li = (function() {
 96                     var last_selected = null;
 97                     return function(li) {
 98                         if( last_selected == li )
 99                             return;
100                         if( last_selected )
101                             last_selected.className = "";
102                         last_selected = li;
103                         last_selected.className = "selected";
104                         document.getElementById("right-panel").innerHTML = last_selected.firstChild.nextSibling.innerHTML;
105                         return false;
106                     };
107                 })();
108                 
109                 var patch_timestamp = function() {
110                     var spans = document.getElementsByTagName("span");
111                     var len = spans.length;
112                     for( var i = 0; i < len; ++i ) {
113                         var span = spans[i];
114                         if( "patch_timestamp" == span.className )
115                             span.innerHTML = new Date( parseInt( span.innerHTML ) );
116                     }
117                 };
118                 
119                 var patch_navigation_class = (function() {
120                 
121                     var set_class = function(el, flag) {
122                         if(el) {
123                             el.className += flag ? " success" : " failure";
124                         }
125                     };
126                 
127                     var traverse = function(el, group_el, flag) {
128                         while(1) {
129                             if(el) {
130                                 if(el.className == 'navigation') {
131                                     set_class(group_el, flag);
132                                     group_el = el;
133                                     flag = true;
134                                 } else {
135                                     var o = el.firstChild;
136                                     o = o ? o.className : null;
137                                     flag = flag ? (o == 'success') : false;
138                                 }
139                                 el = el.nextSibling;
140                             } else {
141                                 set_class(group_el, flag);
142                                 break;
143                             }
144                         }
145                     };
146                     
147                     return function() {
148                         var o = document.getElementById("result-list");
149                         o = o ? o.firstChild : null;
150                         if(o)
151                             traverse(o, null, true);
152                     };
153                 })();
154         
155                 window.onload = function() {
156                     patch_timestamp();
157                     patch_navigation_class();
158                     var o = document.getElementById("result-list");
159                     o = o ? o.firstChild : null;
160                     o = o ? o.nextSibling : null;
161                     if(o)
162                         onclick_li(o);
163                 };
164                 function checkfailure() {
165                     if (document.getElementById("bt").innerHTML == "查看失败") {
166                         document.getElementById("bt").innerHTML = "查看全部";
167                         var trs = document.getElementsByTagName("table")[1].getElementsByTagName('tr');
168                         for( var i = 1; i < trs.length; i++ ) {
169                             var tr = trs[i];
170                             if( "Failure" != tr.className )
171                                 tr.style.display = 'none';
172                         }
173                     }else if(document.getElementById("bt").innerHTML == "查看全部") {
174                         document.getElementById("bt").innerHTML = "查看失败";
175                         var trs = document.getElementsByTagName("table")[1].getElementsByTagName('tr');
176                         for( var i = 1; i < trs.length; i++ ) {
177                             var tr = trs[i];
178                             if( "Failure" != tr.className )
179                                 tr.style.display = '';
180                         }
181                     }
182                 };
183         
184             ]]></script>
185         </head>
186         <body>
187             <h2>Summary</h2>
188             <table  align="center" class="details" cellpadding="5" cellspacing="2" width="100%" >
189                 <tr valign="top">
190                     <th>执行总数</th>
191                     <th>成功数</th>
192                     <th>失败数</th>
193                     <th>成功率</th>
194                     <th>Average Time</th>
195                     <th>Min Time</th>
196                     <th>Max Time</th>
197                 </tr>
198                 <tr valign="top">
199                     <xsl:variable name="allCount" select="count(/testResults/*)" />
200                     <xsl:variable name="allFailureCount" select="count(/testResults/*[attribute::s='false'])" />
201                     <xsl:variable name="allSuccessCount" select="count(/testResults/*[attribute::s='true'])" />
202                     <xsl:variable name="allSuccessPercent" select="$allSuccessCount div $allCount" />
203                     <xsl:variable name="allTotalTime" select="sum(/testResults/*/@t)" />
204                     <xsl:variable name="allAverageTime" select="$allTotalTime div $allCount" />
205                     <xsl:variable name="allMinTime">
206                         <xsl:call-template name="min">
207                             <xsl:with-param name="nodes" select="/testResults/*/@t" />
208                         </xsl:call-template>
209                     </xsl:variable>
210                     <xsl:variable name="allMaxTime">
211                         <xsl:call-template name="max">
212                             <xsl:with-param name="nodes" select="/testResults/*/@t" />
213                         </xsl:call-template>
214                     </xsl:variable>
215                     <xsl:attribute name="class">
216                         <xsl:choose>
217                             <xsl:when test="$allFailureCount &gt; 0">Failure</xsl:when>
218                         </xsl:choose>
219                     </xsl:attribute>
220                     <td align="center">
221                         <xsl:value-of select="$allCount" />
222                     </td>
223                     <td align="center">
224                         <xsl:value-of select="$allSuccessCount" />
225                     </td>
226                     <td align="center">
227                         <xsl:value-of select="$allFailureCount" />
228                     </td>
229                     <td align="center">
230                         <xsl:call-template name="display-percent">
231                             <xsl:with-param name="value" select="$allSuccessPercent" />
232                         </xsl:call-template>
233                     </td>
234                     <td align="center">
235                         <xsl:call-template name="display-time">
236                             <xsl:with-param name="value" select="$allAverageTime" />
237                         </xsl:call-template>
238                     </td>
239                     <td align="center">
240                         <xsl:call-template name="display-time">
241                             <xsl:with-param name="value" select="$allMinTime" />
242                         </xsl:call-template>
243                     </td>
244                     <td align="center">
245                         <xsl:call-template name="display-time">
246                             <xsl:with-param name="value" select="$allMaxTime" />
247                         </xsl:call-template>
248                     </td>
249                 </tr>
250             </table>
251             <button class="button" id="bt" onclick="checkfailure()" style="float:right">查看失败</button>
252             <h2>Pages</h2>
253             <table align="center" class="details" cellpadding="5" cellspacing="2" width="100%">
254                 <tr valign="top">
255                     <th width="30%">URL</th>
256                     <th>执行总数</th>
257                     <th>失败</th>
258                     <th>成功率</th>
259                     <th>Average Time</th>
260                     <th>Min Time</th>
261                     <th>Max Time</th>
262                 </tr>
263                 <xsl:for-each select="/testResults/*[not(@lb = preceding::*/@lb)]">
264                     <xsl:variable name="label" select="@lb" />
265                     <xsl:variable name="count" select="count(../*[@lb = current()/@lb])" />
266                     <xsl:variable name="failureCount" select="count(../*[@lb = current()/@lb][attribute::s='false'])" />
267                     <xsl:variable name="successCount" select="count(../*[@lb = current()/@lb][attribute::s='true'])" />
268                     <xsl:variable name="successPercent" select="$successCount div $count" />
269                     <xsl:variable name="totalTime" select="sum(../*[@lb = current()/@lb]/@t)" />
270                     <xsl:variable name="averageTime" select="$totalTime div $count" />
271                     <xsl:variable name="minTime">
272                         <xsl:call-template name="min">
273                             <xsl:with-param name="nodes" select="../*[@lb = current()/@lb]/@t" />
274                         </xsl:call-template>
275                     </xsl:variable>
276                     <xsl:variable name="maxTime">
277                         <xsl:call-template name="max">
278                             <xsl:with-param name="nodes" select="../*[@lb = current()/@lb]/@t" />
279                         </xsl:call-template>
280                     </xsl:variable>
281                     <tr valign="top">
282                         <xsl:attribute name="class">
283                             <xsl:choose>
284                                 <xsl:when test="$failureCount &gt; 0">Failure</xsl:when>
285                             </xsl:choose>
286                         </xsl:attribute>
287                         <td align="left">
288                             <xsl:value-of select="$label" />
289                         </td>
290                         <td align="center">
291                             <xsl:value-of select="$count" />
292                         </td>
293                         <td align="center">
294                             <xsl:value-of select="$failureCount" />
295                         </td>
296                         <td align="center">
297                             <xsl:call-template name="display-percent">
298                                 <xsl:with-param name="value" select="$successPercent" />
299                             </xsl:call-template>
300                         </td>
301                         <td align="center">
302                             <xsl:call-template name="display-time">
303                                 <xsl:with-param name="value" select="$averageTime" />
304                             </xsl:call-template>
305                         </td>
306                         <td align="center">
307                             <xsl:call-template name="display-time">
308                                 <xsl:with-param name="value" select="$minTime" />
309                             </xsl:call-template>
310                         </td>
311                         <td align="center">
312                             <xsl:call-template name="display-time">
313                                 <xsl:with-param name="value" select="$maxTime" />
314                             </xsl:call-template>
315                         </td>
316                     </tr>
317                 </xsl:for-each>
318             </table>
319 
320             <h2>ErrorDetail</h2>
321             <div id="panel-wrap">
322             <div id="left-panel">
323                 <ol id="result-list">
324                     <!-- 只把失败的生成html -->
325                     <xsl:for-each select="*[attribute::s='false']">
326                         <!-- group with the previous sibling -->
327                         <xsl:if test="position() = 1 or @tn != preceding-sibling::*[1]/@tn">
328                             <li class="navigation">Thread: <xsl:value-of select="@tn"/></li>
329                         </xsl:if>
330                         <li onclick="return onclick_li(this);">
331                             <div>
332                                 <xsl:attribute name="class">
333                                     <xsl:choose>
334                                         <xsl:when test="@s = 'true'">success</xsl:when>
335                                         <xsl:otherwise>failure</xsl:otherwise>
336                                     </xsl:choose>
337                                 </xsl:attribute>
338                                 <xsl:value-of select="@lb"/>
339                             </div><div class="detail">
340                                 <div class="group">Sampler</div>
341                                 <div class="zebra">
342                                     <table>
343                                         <tr><td class="data key">Timestamp</td><td class="data delimiter">:</td><td class="data"><span class="patch_timestamp"><xsl:value-of select="@ts"/></span></td></tr>
344                                         <tr><td class="data key">Time</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="@t"/> ms</td></tr>
345                                         <tr><td class="data key">Latency</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="@lt"/> ms</td></tr>
346                                         <tr><td class="data key">Sample Count</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="@sc"/></td></tr>
347                                         <tr><td class="data key">Error Count</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="@ec"/></td></tr>
348                                         <tr><td class="data key">Response Code</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="@rc"/></td></tr>
349                                         <tr><td class="data key">Response Message</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="@rm"/></td></tr>
350                                     </table>
351                                 </div>
352                                 <div class="trail"></div>
353                                 <xsl:if test="count(assertionResult) &gt; 0">
354                                     <div class="group">Assertion</div>
355                                     <div class="zebra">
356                                         <table>
357                                             <xsl:for-each select="assertionResult">
358                                                 <tbody>
359                                                     <xsl:attribute name="class">
360                                                         <xsl:choose>
361                                                             <xsl:when test="failure = 'true'">failure</xsl:when>
362                                                             <xsl:when test="error = 'true'">failure</xsl:when>
363                                                         </xsl:choose>
364                                                     </xsl:attribute>
365                                                     <tr><td class="data assertion" colspan="3"><xsl:value-of select="name"/></td></tr>
366                                                     <tr><td class="data key">Failure</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="failure"/></td></tr>
367                                                     <tr><td class="data key">Error</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="error"/></td></tr>
368                                                     <tr><td class="data key">Failure Message</td><td class="data delimiter">:</td><td class="data"><xsl:value-of select="failureMessage"/></td></tr>
369                                                 </tbody>
370                                             </xsl:for-each>
371                                         </table>
372                                     </div>
373                                     <div class="trail"></div>
374                                 </xsl:if>
375                                 <div class="group">Request</div>
376                                 <div class="zebra">
377                                     <table>
378                                         <tr><td class="data key">Method/Url</td><td class="data delimiter">:</td><td class="data"><pre class="data"><xsl:value-of select="method"/><xsl:text> </xsl:text><xsl:value-of select="java.net.URL"/></pre></td></tr>
379                                         <tr><td class="data key">Query String</td><td class="data delimiter">:</td><td class="data"><pre class="data"><xsl:value-of select="queryString"/></pre></td></tr>
380                                     </table>
381                                 </div>
382                                 <div class="trail"></div>
383                                 <div class="group">Response</div>
384                                 <div class="zebra">
385                                     <table>
386                                         <tr><td class="data key">Response Data</td><td class="data delimiter">:</td><td class="data"><pre class="data"><xsl:value-of select="responseData"/></pre></td></tr>
387                                     </table>
388                                 </div>
389                                 <div class="trail"></div>
390                             </div>
391                         </li>
392                     </xsl:for-each>
393                 </ol>
394             </div>
395             <div id="right-panel"></div>
396         </div>
397         </body>
398         </html>
399     </xsl:template>
400 
401 
402     <xsl:template name="min">
403         <xsl:param name="nodes" select="/.." />
404         <xsl:choose>
405             <xsl:when test="not($nodes)">NaN</xsl:when>
406             <xsl:otherwise>
407                 <xsl:for-each select="$nodes">
408                     <xsl:sort data-type="number" />
409                     <xsl:if test="position() = 1">
410                         <xsl:value-of select="number(.)" />
411                     </xsl:if>
412                 </xsl:for-each>
413             </xsl:otherwise>
414         </xsl:choose>
415     </xsl:template>
416 
417     <xsl:template name="max">
418         <xsl:param name="nodes" select="/.." />
419         <xsl:choose>
420             <xsl:when test="not($nodes)">NaN</xsl:when>
421             <xsl:otherwise>
422                 <xsl:for-each select="$nodes">
423                     <xsl:sort data-type="number" order="descending" />
424                     <xsl:if test="position() = 1">
425                         <xsl:value-of select="number(.)" />
426                     </xsl:if>
427                 </xsl:for-each>
428             </xsl:otherwise>
429         </xsl:choose>
430     </xsl:template>
431 
432     <xsl:template name="display-percent">
433         <xsl:param name="value" />
434         <xsl:value-of select="format-number($value,'0.00%')" />
435     </xsl:template>
436 
437     <xsl:template name="display-time">
438         <xsl:param name="value" />
439         <xsl:value-of select="format-number($value,'0 ms')" />
440     </xsl:template>
441 
442 </xsl:stylesheet>

  可以将该段代码写入一个.xsl文件中,在build.xml文件中指向该样式。对了,还有一个需要注意的地方,就是,务必将Build.xml文件的编码格式和该样式的编码格式统一,不然,构建之后会出现中文乱码的情况。

  

  看看生成的报告样式。

  

  该模板完全适用于接口自动化框架中。

 

posted @ 2018-03-22 15:01  紫陌花间客  阅读(1521)  评论(0编辑  收藏  举报