Jenkins+Robot Framework持续集成配置(二)

一、用例结果发送邮件配置:

1、在任务配置的 Default Content里配置${SCRIPT,template="robot_results.groovy"}

 

 2、在jenkins主目录下创建email-templates文件夹,将robot_results.groovy放在email-templates文件夹下

<%  
 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:#8F8F8F;
    text-align: center;
}
td.suite{background-color:#EEE8AA;}
td.case{background-color:#dff0d8;}
td.head{background-color:#8F8F8F;}
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> 
                    </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>  
                    </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>

 记得文件保存时用uft-8保存,不然会出现中文乱码

3、安装groovy-postbuild插件

我这是已安装的,未安装在可选插件里,安装完后,重启jenkins

输入:http://地址/restart 可以重启

二、问题及解决

1、如果jenkins无法更新插件

有如下报错:

sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:146)
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:131)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382)
Caused: sun.security.validator.ValidatorException: PKIX path building failed
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387)

解决方法: 安装skip-certificate-check 插件

2、发送的邮件模板未生效

 

解决方法:更新 Email Extension Plugin 插件,我是更新到了2.86版本才好使

3、邮件模板出现中文乱码

解决办法:保存文件时使用utf-8保存

上一篇

Jenkins+Robot Framework持续集成配置(一)_新雪兰的博客-CSDN博客_jenkins robotframework

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
JenkinsRobot Framework中,你可以使用邮件模板来发送测试报告。以下是一个示例的邮件模板: ``` Dear Team, 以下是最新的测试报告摘要: - 总体结果:\[1\] - 通过的测试用例数:\[2\] - 失败的测试用例数:\[3\] - 重跑的测试用例数:\[4\] 你可以在附件中找到完整的测试报告。 请注意,如果你在启动Jenkins时遇到了启动不了Robot的问题,你可能需要安装Robot Framework Plugin插件的2.0.1版本。其他版本可能会导致错误。 如果你在发送邮件时遇到了证书路径错误的问题,你可以尝试以下解决方法: 1. 确保你的证书路径是正确的,并且可以被访问到。 2. 检查你的Jenkins配置,确保你已经正确配置了证书路径。 3. 如果问题仍然存在,你可以尝试手动导入证书到Jenkins的证书存储中。 如果你想要重跑失败的测试用例并合并报告,你可以使用以下命令: call pybot.bat --outputdir R1 C:\Aisa_auto\测试用例\ call pybot.bat -R R1\output.xml --outputdir R2 C:\Aisa_auto\测试用例\ Rebot -o output.xml -R R1\output.xml R2\output.xml 希望以上信息对你有帮助。如果你有任何其他问题,请随时向我提问。 谢谢! Best regards, \[Your Name\] ``` 希望这个邮件模板能满足你的需求。如果你有任何其他问题,请随时向我提问。 #### 引用[.reference_title] - *1* [Jenkins + RobotFramework 构建完成发送邮件](https://blog.csdn.net/q915730058/article/details/108583449)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Jenkins+Robot Framework持续集成配置)](https://blog.csdn.net/weixin_40748006/article/details/122108730)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Jenkins+Robot Framework持续集成配置(一)](https://blog.csdn.net/weixin_40748006/article/details/107641980)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值