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">
    from="" subject="Sanity & Regression Suite Automation Report"
    mailhost="" mailport="465" ssl="true"
    user="" password="*****">

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

 Environment : ${baseURL}

 Automation Team

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

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

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

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..!