Monday, October 21, 2013

HTML templates for JENKINS email-ext to report TestNG results


If you are using testNG and Jenkins Here is a template that I designed. No these are not the conventional templates for jenkins using groovy scripts. Just a plain HTML template that does that job and looks neat. The trend Map will work if you are using Jenkins JUNIT reports from xml

<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 Width="100%">

<TR  BGCOLOR="#989898" width="100%"><td colspan=2><FONT COLOR=White FACE="Geneva, Arial" SIZE=2>  Summary</font></td></TR>

<TR><TD BGCOLOR="#0099CC" width="20%"><FONT COLOR=White FACE="Geneva, Arial" SIZE=2>  Total</font></td><TD BGCOLOR="#FFFFFF"><FONT COLOR=#0099CC FACE="Geneva, Arial" SIZE=2>${TEST_COUNTS,var="total"}</font></td></TR>

<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 Width="100%">
<TR><TD BGCOLOR="#04B431" width="20%"><FONT COLOR=white FACE="Geneva, Arial" SIZE=2>  Pass</font></td><TD BGCOLOR="#FFFFFF"><FONT COLOR=#04B431 FACE="Geneva, Arial" SIZE=2>${TEST_COUNTS,var="pass"}</font></td></TR>

<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 Width="100%">
<TR><TD BGCOLOR="#DF3A01" width="20%"><FONT COLOR=white FACE="Geneva, Arial" SIZE=2>  Fail</font></td><TD BGCOLOR="#FFFFFF"><FONT COLOR=#DF3A01 FACE="Geneva, Arial" SIZE=2>${TEST_COUNTS,var="fail"}</font></td></TR>

<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 Width="100%">
<TR><TD BGCOLOR="#A4A4A4" width="20%"><FONT COLOR=white FACE="Geneva, Arial" SIZE=2>  Skip</font></td><TD BGCOLOR="#FFFFFF"><FONT COLOR=#A4A4A4 FACE="Geneva, Arial" SIZE=2>${TEST_COUNTS,var="skip"}</font></td></TR>

</TABLE>
<br/>
<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 Width="100%">
<TR  BGCOLOR="#989898" width="100%"><td><FONT COLOR=White FACE="Geneva, Arial" SIZE=2>  Failure Analysis</font></td></TR>
<TR  BGCOLOR="#424242" width="100%"><td><FONT COLOR=White FACE="Courier New, Lucida Console" SIZE=2>${FAILED_TESTS, showStack=false}</font></td></TR>
</TABLE>

<br/>
<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 Width="100%">
<TR  BGCOLOR="#989898" width="100%"><td><FONT COLOR=White FACE="Geneva, Arial" SIZE=2>HTML Report</font></td></TR>
<TR  width="100%"><td><FONT FACE="Geneva, Arial" SIZE=2>${JOB_URL}ws/path/to-your-html-report</font></td></TR>
</TABLE>
<br/>


<br/>
<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 Width="100%">
<TR  BGCOLOR="#989898" width="100%"><td><FONT COLOR=White FACE="Geneva, Arial" SIZE=2>Jenkins Job URL</font></td></TR>
<TR  width="100%"><td><FONT FACE="Geneva, Arial" SIZE=2>${JOB_URL}</font></td></TR>
</TABLE>

<br/>
<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 Width="100%">
<TR  BGCOLOR="#989898" width="100%"><td><FONT COLOR=White FACE="Geneva, Arial" SIZE=2>Test Trend</font></td></TR>
<TR width="100%"><td><img lazymap="${JOB_URL}test/trendMap" src="${JOB_URL}test/trend" alt="Trend Graph - Enable Email Images To View" usemap="${JOB_URL}test/trendMap#map0">
</TR>
</TABLE>



What you need to do is-  setup the Email-Ext extension well. To report on failures and success (don't rely on the default). Also attach you screenshots/ reports in email.

~joviano_dias@hotmail.com

3 comments:

  1. Hello!
    I'm writing regarding this line: ${TEST_COUNTS,var="pass"}
    As far as I understand, for this I have to create a parameter pass. But how should I know how many tests are going to pass?

    Regards,
    Karina

    ReplyDelete
    Replies
    1. Karina you have to have a junit xml in your jenkins job. Your tests should output a junit xml. Once you have this, you use the Publish Junit Test Results Report jenkins post build action (think its a plugin) to point to this juni xml.

      This ${TEST_COUNTS,var="pass"} just reads the content picked from the junit xml then

      cheers

      Delete
  2. I had one doubt. I understand parameters like $FAILED_TESTS are being loaded from the junit.xml. But how does it extract these values. I mean to ask how does it assigns values to these variables from the information in junit.xml. I had a task in hand in which, I need to tweak the failed tests parameter to send emails in . a selected format. Thanks in advance

    ReplyDelete