• RobotFramework与Jenkins集成后发送groovy报告(比别处多了用例作者信息)


    https://www.cnblogs.com/gcgc/p/10037891.html

    这篇文章中最终的发送报告是这个样子,每天大家看到这封邮件后也不知道是不是自己的用例错误了,导致大家不积极回复邮件说明失败原因,

     经过修改robot_results.groovy文件内容,将【Elapsed Time】列修改为【作者】

    优化后如下:

     在写case时,只要约定每条用例的第一个tags写上作者的名字,同时略微修改robot_results.groovy文件,将显示时间的代码注释掉,换为获取tag的代码,

    主要就是这行,<td class="case"><%= tc.tags[0] %></td>,用来获取用例的第一个tag

    <%  
     import java.text.DateFormat  
     import java.text.SimpleDateFormat  
    %> 
    <!-- Robot Framework Results --> 
    <!DOCTYPE html>
    <html>
    <style type="text/css">
    table {width:720px;table-layout:fixed;}
    td {width:180px;}
    td.title {
        background-color:#CCFF99;
        text-align: center;
    }
    td.suite{background-color:#EEE8AA;}
    td.case{background-color:#dff0d8;}
    td.head{background-color:#1E90FF;}
    td.error {background-color:#FF6666;}
    table thead tboday tr td {cellspacing:0px;border:1px;}
    h2.span{color:white;}
    span.pass{color:#66CC00;}
    span.fail{color:#FF3333;}
    </style>
    <body>
    <%  
     def robotResults = false  
     def actions = build.actions // List<hudson.model.Action>  
     actions.each() { action ->  
        if( action.class.simpleName.equals("RobotBuildAction") ) { // hudson.plugins.robot.RobotBuildAction  
            robotResults = true 
    %>
            <div>
                <table cellpadding="4" align="left">
                    <thead>
                        <tr>
                            <td class="title" colspan="4"><h2><span>${project.name}</span><span>  自动化测试报告</span></h2></td>
                        </tr>
                        <tr>
                            <td class="case"><b>详细报告</b></td>
                            <td colspan="3" class="case"><a href="${rooturl}${build.url}robot/report/report.html">点击查看报告详情</a></td>
                        </tr>
                        <tr>
                            <td class="head"><b>用例总数</b></td>
                            <td class="head"><b>通过</b></td>
                            <td class="head"><b>不通过</b></td>
                            <td class="head"><b>通过率</b></td>
                        </tr>
                        <tr>
                            <td class="case"><%= action.result.overallTotal %></td>
                            <td class="case"><b><span class="pass"><%= action.result.overallPassed %></span></b></td>
                            <td class="case"><b><span class="fail"><%= action.result.overallFailed %></span></b></td>
                            <td class="case"><%= action.overallPassPercentage %>%</td>
                        </tr>
                        <tr>
                            <td colspan="2" class="head"><b>Test Name</b></td> 
                            <td class="head"><b>Status</b></td>
                            <!-- <td class="head"><b>Elapsed Time</b></td> -->
                            <!-- 将这里的运行持续时间修改为该用例的第一个tag,也就是作者 -->
                            <td class="head"><b>作者</b></td> 
                        </tr>
                    </thead>
                    <tboday>
    <% 
     def suites = action.result.allSuites  
     suites.each() { suite ->   
        def currSuite = suite  
        def suiteName = currSuite.displayName  
        //忽略最上层结构两个占位的元素  
        while (currSuite.parent != null && currSuite.parent.parent != null) {  
            currSuite = currSuite.parent  
            suiteName = currSuite.displayName + "." + suiteName  
        }
    %> 
                        <tr>
                            <td colspan="4" class="suite"><b><%= suiteName %></b></td>
                        </tr>
    <%  
        DateFormat format = new SimpleDateFormat("yyyyMMdd HH:mm:ss")
        def execDateTcPairs = []
        suite.caseResults.each() { tc ->  
            Date execDate = format.parse(tc.starttime)
            execDateTcPairs << [execDate, tc]
        }
        //按执行日期、显示名称进行排序
        execDateTcPairs = execDateTcPairs.sort{ a,b -> a[1].displayName <=> b[1].displayName }
        execDateTcPairs = execDateTcPairs.sort{ a,b -> a[0] <=> b[0] }
        execDateTcPairs.each() {
            def execDate = it[0]
            def tc = it[1]  
    %>
                        <tr>  
                            <td colspan="2" class="case"><%= tc.displayName %></td>  
                            <td class="case"><b><span style="color:<%= tc.isPassed() ? "#66CC00" : "#FF3333" %>"><%= tc.isPassed() ? "PASS" : "FAIL" %></span></b></td>  
                            <!-- <td class="case"><%= tc.getDuration().intdiv(60000)+"分"+(tc.getDuration()-tc.getDuration().intdiv(60000)*60000).intdiv(1000)+"秒" %></td>  -->
                            <!-- 将这里的运行持续时间修改为该用例的第一个tag,也就是作者 -->
                            <td class="case"><%= tc.tags[0] %></td>
                        </tr>  
            
    <%
            if(tc.errorMsg != null) {
    %>
                        <tr>
                            <td class="error"><b><span>错误描述:</span></b></td>
                            <td class="error" colspan="3"><span><%= tc.errorMsg%></span></td>
                        </tr>
    <%                }%>
    <%  
                } // tests  
            } // suites 
    %>  
                    </tboday>
                </table>
            </div>
    <%  
        } // robot results  
    }  
        if (!robotResults){ 
    %> 
        <p>No Robot Framework test results found.</p>  
    <%}%>
    </body>
    </html>
  • 相关阅读:
    排序算法之直接插入排序
    排序算法之快速排序
    进程内存空间
    python基础13 ---函数模块3(正则表达式)
    python基础12 ---函数模块2
    python基础11 ---函数模块1
    python基础10 ---匿名函数和递归
    python基础9 -----python内置函数2
    python基础8 -----迭代器和生成器
    python基础7 ---python函数
  • 原文地址:https://www.cnblogs.com/gcgc/p/11648543.html
Copyright © 2020-2023  润新知