Jenkins(二)之自定义Robot Framework结果报告
生活随笔
收集整理的這篇文章主要介紹了
Jenkins(二)之自定义Robot Framework结果报告
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目標:
實現RobotFramework的腳本定時自動執行,執行完后自動將結果發送到指定郵箱
前提
1、 配置好Robot Framework的環境,腳本可以正常運行,如果不會請看我之前寫的博客Robot Framework 環境搭建
2、 部署好Jenkins的環境,Jenkins的安裝不是本文的重點,不懂的請問度娘(其實很簡單,裝Tomcat,把Jenkins.war包扔到Tomcat的webapp目錄里)
3、 在Jenkins里安裝好以下插件:Email Extension Plugin、Zentimestamp plugin、Robot Framework plugin
配置
1、進入【系統管理】-【系統設置】進行如下配置:
》設置${BUILD_TIMESTAMP}格式
》配置 Extended E-mail Notification默認設置
2、創建一個任務
3、任務的配置
》設置保留的構建的數量
》設置每天凌晨1點的時候自動執行
》增加構建步驟,類型為:Execute shell
》設置運行RobotFramework腳本的命令,這里用-d 來定義RobotFramework的結果輸出目錄,格式如:
robot -d /結果輸出/${BUILD_TIMESTAMP} /腳本目錄/- 1
這里用${BUILD_TIMESTAMP}環境變量是讓每次構建的結構都放在以日期格式命名的文件夾里
》增加構建后操作步驟Publish Robot Framework test results,配置如下:
》再增加一個構建后操作步驟Editable Email Notification,配置可以默認,也可以根據你的需要來配置,以下是我的配置:
4、自定義RobotFramework結構匯總的郵件模板格式,效果如:
大家是否記得前面 Extended E-mail Notification默認設置里Default Content的值是填寫 ${SCRIPT, template=”robot_results.groovy”}
這里就告訴大家怎么去設置這個模板
在$Jenkins_Home/email-templates目錄(如果沒有email-templates請自行創建)下創建一個robot_results.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 displayNameexecDateTcPairs = 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> <% } %>- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
其中Jenkins_Home的路徑不知道在哪里的話,你可以去看一下系統設置頁面,上面有寫有:
完!
<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/markdown_views-ea0013b516.css"></div>總結
以上是生活随笔為你收集整理的Jenkins(二)之自定义Robot Framework结果报告的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 对比stm32,arm9研究方向
- 下一篇: jitsi各工程编译笔记(一)各工程大概