日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Jenkins(二)之自定义Robot Framework结果报告

發(fā)布時(shí)間:2023/12/16 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Jenkins(二)之自定义Robot Framework结果报告 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

目標(biāo):

實(shí)現(xiàn)RobotFramework的腳本定時(shí)自動執(zhí)行,執(zhí)行完后自動將結(jié)果發(fā)送到指定郵箱

前提

1、 配置好Robot Framework的環(huán)境,腳本可以正常運(yùn)行,如果不會請看我之前寫的博客Robot Framework 環(huán)境搭建

2、 部署好Jenkins的環(huán)境,Jenkins的安裝不是本文的重點(diǎn),不懂的請問度娘(其實(shí)很簡單,裝Tomcat,把Jenkins.war包扔到Tomcat的webapp目錄里)

3、 在Jenkins里安裝好以下插件:Email Extension Plugin、Zentimestamp plugin、Robot Framework plugin

配置

1、進(jìn)入【系統(tǒng)管理】-【系統(tǒng)設(shè)置】進(jìn)行如下配置:

》設(shè)置${BUILD_TIMESTAMP}格式


》配置 Extended E-mail Notification默認(rèn)設(shè)置


2、創(chuàng)建一個(gè)任務(wù)


3、任務(wù)的配置

》設(shè)置保留的構(gòu)建的數(shù)量


》設(shè)置每天凌晨1點(diǎn)的時(shí)候自動執(zhí)行


》增加構(gòu)建步驟,類型為:Execute shell


》設(shè)置運(yùn)行RobotFramework腳本的命令,這里用-d 來定義RobotFramework的結(jié)果輸出目錄,格式如:

robot -d /結(jié)果輸出/${BUILD_TIMESTAMP} /腳本目錄/
  • 1

這里用${BUILD_TIMESTAMP}環(huán)境變量是讓每次構(gòu)建的結(jié)構(gòu)都放在以日期格式命名的文件夾里


》增加構(gòu)建后操作步驟Publish Robot Framework test results,配置如下:


》再增加一個(gè)構(gòu)建后操作步驟Editable Email Notification,配置可以默認(rèn),也可以根據(jù)你的需要來配置,以下是我的配置:


4、自定義RobotFramework結(jié)構(gòu)匯總的郵件模板格式,效果如:


大家是否記得前面 Extended E-mail Notification默認(rèn)設(shè)置里Default Content的值是填寫 ${SCRIPT, template=”robot_results.groovy”}

這里就告訴大家怎么去設(shè)置這個(gè)模板

在$Jenkins_Home/email-templates目錄(如果沒有email-templates請自行創(chuàng)建)下創(chuàng)建一個(gè)robot_results.groovy文件,內(nèi)容如下:

<% 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ào)告</b></td> </tr><tr><td bgcolor="#F3F3F3" style="width:80px"><b>詳細(xì)報(bào)告:</b></td><td colspan="4"><a href="${rooturl}${build.url}robot/report/report.html">點(diǎn)擊查看報(bào)告詳情</a></td></tr> <tr bgcolor="#F3F3F3"><td><b>用例總數(shù)</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">錯(cuò)誤描述:</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">*這個(gè)是通過Jenkins自動構(gòu)建得出的報(bào)告,僅供參考。</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的路徑不知道在哪里的話,你可以去看一下系統(tǒng)設(shè)置頁面,上面有寫有:

完!

<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/markdown_views-ea0013b516.css"></div>

總結(jié)

以上是生活随笔為你收集整理的Jenkins(二)之自定义Robot Framework结果报告的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。