0

我正在为我的 geb spock html 报告使用 athaydes 报告。我正在尝试修改 html 报告以获取测试用例的状态。为此,我添加了新列作为“最后一列”下面是我正在使用的 html:

<table class="summary-table">
    <thead>
    <tr>
        <th>Name</th>
        <th>Features</th>
        <th>Failed</th>
        <th>Errors</th>
        <th>Skipped</th>
        <th>Time</th>
        <th>Final Status</th>
    </tr>
    </thead>
    <tbody>
    <% data.each { name, map ->
    def s = map.stats%>
    <tr class="${s.errors ? 'error' : ''} ${s.failures ? 'failure' : ''} ">
        <td><a href="${name}.html">$name</a></td>
        <td>${s.totalRuns}</td>
        <td>${s.failures}</td>
        <td>${s.errors}</td>
        <td>${s.skipped}</td>
        <td>${fmt.toTimeDuration(s.time)}</td>
        <td if="${s.totalRuns} != 0" ? 'PASS' : 'FAILED >${s.totalRuns = 0 ? 'PASS' : 'FAILED' }</td>
    </tr>
    <% } %>
    </tbody>
</table>

现在我的要求是,如果“ ${s.failures}”和“ ${s.errors}”和“ ${s.skipped}”都等于零,那么只有列的值应该是“PASS”,否则它应该是“FAILED”。

我尝试了类似的 方法,<td if="${s.totalRuns} != 0" ? 'PASS' : 'FAILED >${s.totalRuns = 0 ? 'PASS' : 'FAILED' }</td> 但是这个解决方案不起作用,因为我对 html 很陌生。

你能在这方面帮助我吗?谢谢!

4

1 回答 1

1

您可以使用以下代码片段,如果发生故障、错误或跳过测试,则显示 FAILED,否则显示 PASS:

<td>${ s.failures || s.errors || s.skipped ? 'FAILED' : 'PASS' }</td>

由于s.failures和其他都是整数,我们不需要显式检查它们是否大于 0。

如果您还想隐藏s.totalRuns零值,您可以添加另一个条件。一般经验法则:两者之间的一切都<% ... %>可以是任何 Groovy 代码。可能有比这个更清洁的解决方案,但它可以解决问题:

<td>
    <% if (s.totalRuns) { %>
        ${ s.failures || s.errors || s.skipped ? 'FAILED' : 'PASS' }
    <% } %>
</td>
于 2018-05-14T19:19:21.230 回答