如何在每个测试用例中获得电子邮件ext groovy脚本中的所有robotframework警告? 背景
下面是配置的背景如何在每个测试用例中获得电子邮件ext groovy脚本中的所有robotframework警告? 背景,groovy,jenkins,jenkins-plugins,robotframework,email-ext,Groovy,Jenkins,Jenkins Plugins,Robotframework,Email Ext,下面是配置的背景 我有用Robot框架编写的测试 我使用Jenkins并安装了robotframework和email ext插件 我计划定期运行Jenkins作业 詹金斯·乔布斯负责机器人测试 然后发送一封包含测试结果的电子邮件(使用email ext) 我正在使用groovy脚本生成电子邮件内容 生成电子邮件内容的groovy脚本正在使用获取数据(例如:测试总数、失败总数、通过百分比)和所有失败测试用例的信息 对于所有失败的测试用例,RoboCaseResult列表,我包括:
- 我有用Robot框架编写的测试
- 我使用Jenkins并安装了robotframework和email ext插件
- 我计划定期运行Jenkins作业
- 詹金斯·乔布斯负责机器人测试
- 然后发送一封包含测试结果的电子邮件(使用email ext)
- 我正在使用groovy脚本生成电子邮件内容
- 我计划定期运行Jenkins作业
- 测试临界性
- 父套件
- 测试名称
- 错误消息
def actionslist = build.actions // List<hudson.model.Action>
def doRobotResultsExist = false
actionslist.each() { action ->
if( action.class.simpleName.equals("RobotBuildAction") ) { // hudson.plugins.robot.RobotBuildAction
doRobotResultsExist = true
displaycritical = (action.getOverallPassPercentage() != action.getCriticalPassPercentage())
%>
<h3>RobotFramework Results</h3>
<table>
<tr>
<td>Detailed Report:</td>
<td><a href="${rooturl}${build.url}robot/report/<%= action.getLogHtmlLink() %>" target="_new"><%= action.getLogHtmlLink() %></a></td>
</tr>
<!--
<tr>
<td>Pass Percentage:</td>
<td><%= action.overallPassPercentage %>%</td>
</tr>
-->
<tr>
<td>Overall Pass Ratio:</td>
<td><%= action.getTotalCount() - action.getFailCount() %>/<%= action.getTotalCount() %></td>
</tr>
<tr>
<td>Pass Percentage:</td>
<td><%= action.getOverallPassPercentage() %>%</td>
</tr>
<%
if (displaycritical) {
%>
<tr>
<td>Critical Pass Percentage:</td>
<td><%= action.getCriticalPassPercentage() %>%</td>
</tr>
<% } //if displaycrital %>
<tr>
<td>Total Failed:</td>
<td><%= action.getFailCount() %></td>
</tr>
</table>
<%
//action.result returns hudson.plugins.robot.model.RobotResult
//action.retult.getAllFailedCases() returns a list of hudson.plugins.robot.model.RobotCaseResult
def allFailedTests = action.result.getAllFailedCases() // hudson.plugins.robot.model.RobotCaseResult
if (!allFailedTests.isEmpty()) {
i = 0
%>
<table cellspacing='0' cellpadding='1' border='1'>
<tr class='bg1'>
<% if (displaycritical) { %><th>Tagged Critical</th><% } //if displaycrital %>
<th>Suite</th>
<th>Failed Test Case</th>
<th>Error message</th>
</tr>
<%
//allFailedTests.each() { testresult ->
// def testCaseResult = testresult
allFailedTests.each() { testCaseResult ->
i++
print "<tr " + ( (i % 2) == 0 ? "class='bg2'" : "") + " >"
if (displaycritical) {
print "<td>" + (testCaseResult.isCritical()? "<font color='red'><b>YES</b></font>": "no" )+ "</td>"
}
print "<td>" + testCaseResult.getParent().getRelativePackageName(testCaseResult.getParent()) + "</td>"
print "<td>" + testCaseResult.getDisplayName() + "</td>"
print "<td>" + testCaseResult.getErrorMsg() + "</td>"
print "</tr>"
} // for each failed test
%>
</table>
<%
} // if list of failed test cases is not empty
} // end action is RobotBuildAction
} // end of each actions
def actionslist=build.actions//List
def doRobotResultsExist=错误
actionslist.each(){action->
if(action.class.simpleName.equals(“RobotBuildAction”){//hudson.plugins.robot.RobotBuildAction
doRobotResultsExist=正确
displaycritical=(action.getOverallPaspercentage()!=action.getCriticalPaspercentage())
%>
机器人框架结果
详细报告:
整体通过率:
/
通过率:
%
关键通过率:
%
失败总数:
标记关键
一套
失败的测试用例
错误消息
//def testcasesult=testresult
allFailedTests.each(){testCaseResult->
我++
打印“”
如果(显示关键){
打印“”+(testCaseResult.isCritical()?“是”:“否”)+“”
}
打印“+testCaseResult.getParent().getRelativePackageName(testCaseResult.getParent())+”
打印“”+testCaseResult.getDisplayName()+“”
打印“”+testCaseResult.getErrorMsg()+“”
打印“”
}//对于每个失败的测试
%>
我不熟悉robot插件API,所以我不能说您想要的信息是否可以从那里获得。我只知道robot生成的output.xml文件中有这些信息。这个文件很容易解析。下面是一个使用一个log关键字的测试生成的文件的顶部:
<robot generated="20140527 19:46:02.095" generator="Robot 2.8.1 (Python 2.7.2 on darwin)">
<suite source="/tmp/example.robot" id="s1" name="Example">
<test id="s1-t1" name="Example of a warning">
<kw type="kw" name="BuiltIn.Log">
<doc>Logs the given message with the given level.</doc>
<arguments>
<arg>This is a warning</arg>
<arg>warn</arg>
</arguments>
...
您可以通过使用--listener参数来使用它,例如:
pybot --listener ExampleListener.py my_suite
谢谢。我不知道机器人监听器。它工作得很好,不过我不得不修改你提供的示例监听器来满足我的需要。监听器是我最喜欢的机器人功能之一。你可以用它们做很多事情。嘿,你知道使用监听器从机器人文件中获取詹金斯的工作名吗?
<robot generated="20140527 19:46:02.095" generator="Robot 2.8.1 (Python 2.7.2 on darwin)">
<suite source="/tmp/example.robot" id="s1" name="Example">
<test id="s1-t1" name="Example of a warning">
<kw type="kw" name="BuiltIn.Log">
<doc>Logs the given message with the given level.</doc>
<arguments>
<arg>This is a warning</arg>
<arg>warn</arg>
</arguments>
...
class exampleListener():
ROBOT_LISTENER_API_VERSION = 2
def __init__(self, filename="messages.txt"):
self.outfile = open(filename, "w")
self.outfile.write("Errors and Warnings\n")
self.current_test = None
self.current_messages = []
self.current_suite = None
def start_suite(self, name, attrs):
self.current_suite = name
def start_test(self, name, attrs):
self.current_test = name
self.current_messages = []
def log_message(self, data):
self.current_messages.append((data["level"], data["message"]))
def end_test(self, name, attrs):
for (type, text) in self.current_messages:
if type == "ERROR":
self.outfile.write("| %s | %s | %s\n" % (self.current_suite, self.current_test, text))
elif type == "WARN":
self.outfile.write("| %s | %s | | %s\n" % (self.current_suite, self.current_test, text))
self.current_messages = []
self.current_test = None
def end_suite(self, name, attrs):
self.outfile.close()
pybot --listener ExampleListener.py my_suite