CI-持续集成:⑥--jenkins集成robot framework及发送执行报告

1.安装jenkins并可以使用,前面有博客介绍的,需要参考的话可以看看

2.下载对应插件:

3.新建一个项目用于运行robot脚本,在构建后选择操作 publish Robot Framew test result

我是直接通过命令去执行case的

配置一下构建后的操作

配置保存后,外面会有机器人的图标

运行之后,会出现执行情况

 

4.关于robot报告的发送

添加发邮件的构建后操作:Editable Email Notification

配置一下 Default Content,如图:

点击advanced Settings配置一下Triggers

点击高级配置,如下图配置即可

创建../jenkins/email-templates/robot_results.groovy

groovy文件:

<%
 import java.text.DateFormat
 import java.text.SimpleDateFormat
 %>
    <!-- Robot Framework Results -->
<%
 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 style="width:100%;float:left">
                    <table cellspacing="0" cellpadding="4" border="1" align="left">
                        <thead>
                            <tr bgcolor="#F3F3F3">
                                <td style="text-align:center" colspan="4"><b>自动化测试汇总报告</b></td>
                            </tr>
                            <tr>
                                <td bgcolor="#F3F3F3" style="width:80px"><b>详细报告:</b></td>
                                <td colspan="4"><a href="${rooturl}${build.url}robot/report/report.html">点击查看报告详情</a></td>
                            </tr>
                            <tr bgcolor="#F3F3F3">
                                <td><b>用例总数</b></td>
                                <td><b>通过</b></td>
                                <td style="width:60px"><b>不通过</b></td>
                                <td style="width:100px"><b>通过率</b></td>
                            </tr>
                            <tr>
                                <td><%= action.result.overallTotal %></td>
                                <td><b><span style="color:#66CC00"><%= action.result.overallPassed %></span></b></td>
                                <td><b><span style="color:#FF3333"><%= action.result.overallFailed %></span></b></td>
                                <td><%= action.overallPassPercentage %>%</td>
                            </tr>
                            <tr bgcolor="#F3F3F3">
                                <td colspan="2"><b>Test Name</b></td>
                                <td><b>Status</b></td>
                                <td><b>Elapsed Time</b></td>
                            </tr>
                        </thead>
                        <tbody>

<% def suites = action.result.allSuites
   suites.each() { suite ->
    def currSuite = suite
    def suiteName = currSuite.displayName
    // ignore top 2 elements in the structure as they are placeholders
    while (currSuite.parent != null && currSuite.parent.parent != null) {
     currSuite = currSuite.parent
     suiteName = currSuite.displayName + "." + suiteName
    } %>

                            <tr>
                                <td colspan="4"><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]
    }
    // primary sort execDate, secondary displayName
    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"><%= tc.displayName %></td>
                                <td><b><span style="color:<%= tc.isPassed() ? "#66CC00" : "#FF3333" %>"><%= tc.isPassed() ? "PASS" : "FAIL" %></span></b></td>
                                <td><%= tc.getDuration().intdiv(60000)+"分"+(tc.getDuration()-tc.getDuration().intdiv(60000)*60000).intdiv(1000)+"秒" %></td>
                            </tr>
                            <% if(tc.errorMsg != null) {%>
                            <tr>
                                <td ><b><span style="font-size:10px;color:#FF3333">错误描述:</span></b></td>
                                <td colspan="3"><span style="font-size:10px"><%= tc.errorMsg%></span></td>

                            </tr>
                            <%
                             }%>
<%  } // tests
   } // suites %>
                        </tbody>
                    </table>

                     <p style="color:#AE0000;clear:both">*这个是通过Jenkins自动构建得出的报告,仅供参考。</p>
                    </div>
                    <%
  } // robot results
 }
 if (!robotResults) { %>
        <p>No Robot Framework test results found.</p>
<%
 } %>

得到的报告是这样的:

 

曾经遇到的格式不正确的问题,一直都好好的,我们更换版本之后,构建的接口报告格式就出现了问题

经过几番尝试之后,发现这个是因为接口请求报错,返回不规范,导致表格框存不下那么多信息,所以乱掉了

请开发修复好接口的数据返回,这个表格就对了

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值