Robot Framework ResultsDetailed Report Pass Percentage: 80.0%
|
Here is a snippet from the Groovy template that generated the above:
<%
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 %>
<p><h4>Robot Framework Results</h4></p>
<p><a href="${rooturl}${build.url}robot/report/report.html">Detailed Report</a></p>
<p>Pass Percentage: <%= action.overallPassPercentage %>%</p>
<table cellspacing="0" cellpadding="4" border="1" align="center">
<thead>
<tr bgcolor="#F3F3F3">
<td><b>Test Name</b></td>
<td><b>Status</b></td>
<td><b>Execution Datetime</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="3"><b><%= suiteName %></b></td></tr>
<% DateFormat format = new SimpleDateFormat("yyyyMMdd HH:mm:ss.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><%= tc.displayName %></td>
<td style="color: <%= tc.isPassed() ? "#66CC00" : "#FF3333" %>"><%= tc.isPassed() ? "PASS" : "FAIL" %></td>
<td><%= execDate %></td>
</tr>
<% } // tests
} // suites %>
</tbody></table><%
} // robot results
}
if (!robotResults) { %>
<p>No Robot Framework test results found.</p>
<%
} %>
The date conversion is there to convert the date from the format Robot uses to the Java default format, which is more familiar to us.This is the first thing I have ever done in Groovy, and I must say it is a pleasant language to write in. I especially like how getters and setters are mapped to the Groovy concept of properties.
Happy roboting.
is this the groovy script or the template?
ReplyDeletei tried to put your script in the default location and use:
${SCRIPT, robot-mail.groovy}
no luck
It is a template. The value I use for Default Content is:
Delete${SCRIPT, script="email-ext.groovy", template="with_results.groovy", init="false"}
A script that includes the content in this post and a little more is saved in {Jenkins installation folder}/email-templates/with_results.groovy
Hope this helps.
thank you for your quick replay !
Deletenow the script is loaded but it cannot find the robot results:
No Robot Framework test results found.
heres an example of report.html link
http://172.21.161.162:8080/job/7-Global-Report-92/19/label=master/robot/report/report.html
should i edit some thing in the script? (ps i am using windows for jenkins master)
thank you for your help !
The Publish Robot Framework test results must appear before the Editable Email Notification action in the build configuration. Another thing I think that could perhaps be problematic is a matrix build. I would create a dummy job that runs one test and publishes it to troubleshoot. Good Luck.
DeleteHi Kevin
ReplyDeleteThanks for your script, this help me so much.
I need your help, when the script make the table, don't use any order to put the tests. You know how created the table by the run order?
Many regards
Filipe Duarte
I'm glad this was of use to you. For a while I have wanted to put some sorting in. I updated the code to sort the test cases within each suite, but the suites are still un-ordered.
ReplyDeleteHi Kevin,
DeleteI am new to this groovy and robot stuff. can you please explain on how did you make the email-ext.groovy? is it available with jenkins installation by default or something that has to be written from scratch?
Thanks,
SWAMY
Hi Kevin
ReplyDeleteSo many thanks, I test with the new code and work fine.
Many Regards
Filipe Duarte
Hi Kevin,
ReplyDeleteI am new to Robot framework and Jenkins. Will you please elaborate us how these tools are working each other and I would like to get a practical knowledge on them. Please reply as soon as possible..thanks in advance..
I created a dummy suite with a pass and fail test. I looked at the javadocs for the Robot Framework plugin. It was just trial and error, really. I did not use an IDE.
DeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
DeleteHi!
DeleteI can't put this to work in my jenkins. Can you provide the files you're using? The script and the template?
Thanks!
See https://gist.github.com/ombre42/cb6bc804c876a7f07c45#file-gistfile1-txt
DeleteIs there possibility to show error message from robot using this script?
ReplyDeleteThank you so much for the groovy script. I was trying to get email sent from jenkins in a way that its legible and clear. I had to spend two day trying to do it. And finally your groovy script worked like a charm. Thanks again.
ReplyDeleteHi,
DeleteCould you please help me in which location this groovy script has to be placed in the jenkins
It should go in $JENKINS_ROOT/email-templates. In the instances that I have running, this is /var/lib/jenkins/email-templates.
DeleteAlso, there is an 'Email Template Testing' link within the jobs viewer where you can test the email template against any build after you've copied it to email-templates directory.
Just for convenience for any one else who would be struggling like me, I will paste the exact syntax as below :
ReplyDelete${SCRIPT, template="groovy_template.groovy"}
This comment has been removed by the author.
ReplyDeleteI am not good at groovy scripting, but I like this code. Can someone help me modifying this script to display duration(in seconds) of each testcase execution instead of just the starttime - I meant subtracting the endtime with starttime and displaying the result in seconds
ReplyDeleteHi Kevin
ReplyDeleteSo in Jenkins where i need paste the script and get the results in email ?
can you please tell step by step that will be really helpful.
Thank you
@Unknown,
ReplyDeleteYou put this code:
${SCRIPT, template="robot-jobs.groovy"}
in the "Default Content" field of the "Editable Email Notification" in your job.
The "robot-jobs.groovy" file should be placed inside your jenkins_home folder, in "email-templates" subfolder.
Hi Zepgirus,
DeleteCopied the ${SCRIPT, template="robot-jobs.groovy"} in "Default Content" filed in "Editable Email Notification" in my job
And also copied the .groovy file at opt/drutt/ca/jenkins/home/plugins/emailext-template in my Jenkins server
Now trying to run the build but it shows as Robot results publisher started...
-Parsing output xml:
Done!
-Copying log files to build dir:
Done!
-Assigning results to build:
Done!
-Checking thresholds:
Done!
Done publishing Robot results.
No emails were triggered.
Finished: SUCCESS
can you please help me
Thanks
Do you have triggers configured under the Editable Email Notification Advanced settings in your job? If I recall, only the failure condition is enabled by default and I don't recall which 'Send To' group is bound to it. You have to add a trigger for success, unstable, etc. and also either pick a group to send those to and/or manually enter email addresses (you have to click advanced under the trigger that you are adding to manually add an address to send to)
Delete"email-templates" subfolder, not "emailext-template". Maybe it's that?
ReplyDeleteCan you send emails at all?
Can anyone explain me this in bit detail.I need to send the mails but getting this error when i test groovy file in templates.
ReplyDeleteGroovy Template file [robot-jobs.groovy] was not found in $JENKINS_HOME/email-templates.
I have created this folder then also getting same issue.
This post is so useful and informative. Keep updating with more information.....
ReplyDeleteIELTS Certification
IELTS Coaching
Great work with lots of knowledgeable information and thanks for sharing!!
ReplyDeleteGraphic Design Training in Ahmedabad
Graphic Design Training in Trivandrum
Graphic Design Training in Pune