作为一个测试工程师,尤其是做自动化测试的时候,结果展示往往是个重头戏。如何让测试case的结果清晰的展现在大家面前,而不是一堆log堆在那里,确实是要花时间去考虑的。我这边目前采用的是HTML中表格的展示方式,还可以直接在邮件中展示,直观方便。
在制作HTML表格的初期,我就是直接用的最简单的方法,没有任何处理,效果如下:
下面是代码:
<html>
<body>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td>Name</td>
<td>Result</td>
<td>Reason</td>
<td>Comments</td>
</tr>
<tr>
<td>TestCase1</td>
<td>Pass</td>
<td>111</div></td>
<td>This is a comment!</td>
</tr>
<tr>
<td>TestCase2</td>
<td>Fail</td>
<td>java.net.SocketTimeoutException: Read timed out at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) at java.net.SocketInputStream.read(SocketInputStream.java:170) at java.net.SocketInputStream.read(SocketInputStream.java:141) at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:166) at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:90) at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:281) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:92) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:61) at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:254) at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:289) at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:252) at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:191) at org.apache.jmeter.protocol.http.sampler.MeasuringConnectionManager$MeasuredConnection.receiveResponseHeader(MeasuringConnectionManager.java:201) at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:300) at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:127) at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:715) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:520) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805) at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.executeRequest(HTTPHC4Impl.java:517) at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:331) at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74) at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1146) at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1135) at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:434) at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261) at java.lang.Thread.run(Thread.java:745)
</td>
<td>This is a comment!</td>
</tr>
<tr>
<td>TestCase3</td>
<td>Pass</td>
<td>222</td>
<td>This is a comment!</td>
</tr>
<tr>
<td>TestCase4</td>
<td>Pass</td>
<td>333</td>
<td>This is a comment!</td>
</tr>
</table>
</body>
</html>
其实单单从展示结果来说,我们的目的达到了。但是有一点不完美,就是中间的长字符串把我们的其他列挤压的不要不要的,图变得很丑了。怎么优化呢?接下来就来看看我是怎么解决这个问题的。
还是先看效果:
还是很明显的吧!中间的长字符串现在变成了可以滚动的形态,使我们的表格看着舒服多了。话不多说,看代码:
<html>
<body>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td>Name</td>
<td>Result</td>
<td>Reason</td>
<td>Comments</td>
</tr>
<tr>
<td>TestCase1</td>
<td>Pass</td>
<td><div class="sidebar-nav" style="overflow:auto;overflow-x:hidden;width:350px;max-height:350px">111</div></td>
<td>This is a comment!</td>
</tr>
<tr>
<td>TestCase2</td>
<td>Fail</td>
<td><div class="sidebar-nav" style="overflow:auto;overflow-x:hidden;width:350px;max-height:350px">java.net.SocketTimeoutException: Read timed out at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) at java.net.SocketInputStream.read(SocketInputStream.java:170) at java.net.SocketInputStream.read(SocketInputStream.java:141) at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:166) at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:90) at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:281) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:92) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:61) at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:254) at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:289) at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:252) at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:191) at org.apache.jmeter.protocol.http.sampler.MeasuringConnectionManager$MeasuredConnection.receiveResponseHeader(MeasuringConnectionManager.java:201) at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:300) at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:127) at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:715) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:520) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805) at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.executeRequest(HTTPHC4Impl.java:517) at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:331) at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74) at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1146) at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1135) at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:434) at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261) at java.lang.Thread.run(Thread.java:745)
</div></td>
<td>This is a comment!</td>
</tr>
<tr>
<td>TestCase3</td>
<td>Pass</td>
<td><div class="sidebar-nav" style="overflow:auto;overflow-x:hidden;width:350px;max-height:350px">222</div></td>
<td>This is a comment!</td>
</tr>
<tr>
<td>TestCase4</td>
<td>Pass</td>
<td><div class="sidebar-nav" style="overflow:auto;overflow-x:hidden;width:350px;max-height:350px">333</div></td>
<td>This is a comment!</td>
</tr>
</table>
</body>
</html>
Friendly Support :)
http://www.w3school.com.cn/cssref/pr_pos_overflow.asp