Sunday 28 September 2014

Sending e-mail notification using TestNG , ANT and WebDriver

Sending e-mail notifications for daily report of our Test Suite Execution has become an important business requirements in majorly all the on-going projects.

Email notification can be send easily without any typical Java code but via TestNG and WebDriver only.

We will send the notification using one of the features of TestNG and the code for that is :


<!-- @ Purpose: This function is for sending an auto email after sanity & regression
   run is complete. -->

<target name="send-email">
<mail
    tolist="abc@xyz.com"
    cclist="pqr@tuv.com"
    from="efg@hij.com" subject="Sanity & Regression Suite Automation Report"
    mailhost="smtp.gmail.com" mailport="465" ssl="true"
    user="efg@hij.com" password="*****">
   
    <message>Hi,

 PFA the HTML Report of Automation Sanity & Regression Suite Execution.

 Environment : ${baseURL}

 Regards,
 Automation Team

 *** This is an automatically generated email, please do not reply to this email id. ***
    </message>
<attachments>
 <fileset dir="${outputDir}">
      <include name="index.html" />
      <include name="emailable-report.html" />
 </fileset>
</attachments>
</mail>

<tstamp>
   <format property="send.time" pattern="MM/dd/yyyy hh:mm aa" unit="hour" />
</tstamp>

<echo message="Mail successfully sent at ${send.time}" />
</target>


Create a new target for sending e-mail in your build.xml and call that target name to send notification.

Also you need Java Mail API Jar. Download it from here and Activation Jar from here. Put these jars in the lib folder of ANT.

The Email send notification is configured using TestNG, ANT and WebDriver.

Happy E-mailing..!

No comments:

Post a Comment