How to automatically email emailable-report.html after every test run?

7,579 views
Skip to first unread message

Dinesh .M

unread,
Apr 9, 2011, 5:57:29 AM4/9/11
to Selenium Users
Hi Everyone!!

Can anyone tell me how to email the emailable report.html file form
output folder to everyone in my team after the test is run.

Thanks
Dinesh.

Lutfi Dughman

unread,
Apr 9, 2011, 4:29:41 PM4/9/11
to seleniu...@googlegroups.com
assuming you use java

you have to use JavaMAIL   API to send messages and receiver emails, ofcourse you will need an smtp serer which im sure your company has one.


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


ramraj

unread,
Apr 11, 2011, 1:42:40 AM4/11/11
to Selenium Users
Hi,

You could use any mail API based on the your client language.

1.Write a function to send the email about the report.
2.Invoke the the mail function from the TestNG XML file after your
tests are executed.

Regards,
Ramraj

sac

unread,
Jul 31, 2012, 1:30:41 AM7/31/12
to seleniu...@googlegroups.com
Hi Friends,

I am also trying to to send the email-able report aftter execution. 
for that i am calling the send Email function in teardown() . but the issue is that  Selenium Report is generated after the teardown() function is completed. 
and i am calling the Send Email function within teardown. So Send Email function is sending old report not the latest one.

Can any one help me on the same....... teardown code is as below 

@AfterClass
public void tearDown() throws Exception{
selenium.stop();
System.out.println("-----Report Creation Completed: " + System.currentTimeMillis());
Thread.sleep(1000);
SendFileEmail e= new SendFileEmail();
e.sendEmail();
}

   Thanks ,
Sachin

jeevan

unread,
Jul 31, 2012, 1:32:17 AM7/31/12
to seleniu...@googlegroups.com
You can look at @AfterSuite....

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/ZUiYxuCkQj8J.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Mark Collin

unread,
Jul 31, 2012, 1:34:00 AM7/31/12
to seleniu...@googlegroups.com

I don’t see anything there that creates reports.  You’ll need to find the code that creates reports and put the e-mail code after that.

--

Krishnan Mahadevan

unread,
Jul 31, 2012, 2:58:12 AM7/31/12
to seleniu...@googlegroups.com
I am guessing that you are referring to the TestNG generated "emailable-report.html" which you would want to mail.

With that assumption here's how you should be able to do it.

1. Extend org.testng.reporters.EmailableReporter
2. Override org.testng.reporters.EmailableReporter.generateReport(List<XmlSuite>, List<ISuite>, String) and have it do something as below :

@Override
public void generateReport(List<XmlSuite> xml, List<ISuite> suites, String outdir) {
    super.generateReport(xml, suites, outdir);
    SendFileEmail e= new SendFileEmail();
    e.sendEmail();
}

Now add up this listener of yours into your suite file using 
<listeners>
</listeners> 
tag.

That should get you through !


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

Kiruthika

unread,
Jul 31, 2012, 12:47:03 PM7/31/12
to seleniu...@googlegroups.com
Or to keep things simple, write a simple cron job that will email your .html file to the people you want to send it to.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.


To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/ZUiYxuCkQj8J.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

Krishnan Mahadevan

unread,
Jul 31, 2012, 2:02:16 PM7/31/12
to seleniu...@googlegroups.com
Kiruthika,
I believe that cron job (which I understand is the Unix version of task scheduler of windows) runs based on intervals. So am not sure if you can couple that with test execution! If am missing something obvious here would love to hear you elaborate more!
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/4ELXg5vCJvUJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 


--
Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

Kiruthika

unread,
Aug 2, 2012, 11:21:09 AM8/2/12
to seleniu...@googlegroups.com
Krishnan,
I have a simple shell script to run the test suite. And two cron jobs, one to start the test and one to send the report.

E.G:
crontab -e

00 07 * * * /locationOfYourScript.sh
00 08 * * * mail --append="Content-type: text/html" -s "HTML Test Report" -t em...@server.com < /locationOfYourReport.html

P.S: My Code is in SeleniumRC+Java+TestNG

Krishnan Mahadevan

unread,
Aug 2, 2012, 11:23:19 AM8/2/12
to seleniu...@googlegroups.com
Ah ok! So you are running on a "Non Continuous Integration" environment eh. Makes sense !

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/lnqDwyLoPgkJ.

Kiruthika

unread,
Aug 2, 2012, 11:45:05 AM8/2/12
to seleniu...@googlegroups.com
You could also use CruiseControl or TeamCity to schedule your tests.
I use CruiseControl on one environment and cron jobs on other.
To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

Edwolb

unread,
Aug 2, 2012, 1:53:11 PM8/2/12
to seleniu...@googlegroups.com
Hopefully your test takes less than a minute :)

Best way is to do as Krishnan suggested, have the listener kick off the email, that way it happens the right way every time.

--
Chris

Krishnan Mahadevan

unread,
Aug 3, 2012, 5:21:04 AM8/3/12
to seleniu...@googlegroups.com
And if none of that is acceptible, here's a maven plug-in that can do it automatically for you 



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/nQHvtmgDxawJ.

Meenal Jain

unread,
Apr 15, 2014, 8:40:56 AM4/15/14
to seleniu...@googlegroups.com
Hi Everybody,

1) I tried JavaMailAPI to send emailable-report.html as an attachment in email,but every time i get FileNotFoundException because this report is generated after testsuite is completely executed.
I've tried calling sendmail method as @AfterSuite and @AfterTest as well,but nothing is working well.

2) I also tried Maven Postman plugin to send email,Its working fine and sending email with an attachment. But the problem with it is that In case of build failure,it is not sending email.

Any ideas to resolve the issue?

Thanks,
Meenal

Krishnan Mahadevan

unread,
Apr 15, 2014, 8:43:59 AM4/15/14
to Selenium Users
Please see if you can get this sorted out by invoking sendMail() method that you wrote within an IExecutionListener implementation


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

Meenal Jain

unread,
Apr 15, 2014, 9:01:40 AM4/15/14
to seleniu...@googlegroups.com
No,its not working.


--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/XJhpJ-vlu1g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

______________________________________________________________________________________________________
NOTICE: This email and any files transmitted with it, including their content, are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email by mistake, or in error, please notify the sender and/or system manager immediately and delete this e-mail from your system. If you are not the named or intended addressee of this email then you should not disseminate, distribute, copy or disclose this e-mail and you are strictly prohibited from taking any action in reliance on the information contained in this email and any files attached with it.


Although the company has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments.
______________________________________________________________________________________________________

Krishnan Mahadevan

unread,
Apr 15, 2014, 9:37:04 AM4/15/14
to Selenium Users
Umm.. interesting! 

Here's an ugly hack that should get this done! 


package org.rationale.emotions.testng;

import java.io.File;
import java.util.List;

import org.rationale.emotions.testng.ListenerDemo.MyFuzzyListener;
import org.testng.IReporter;
import org.testng.ISuite;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.testng.xml.XmlSuite;

@Listeners({ MyFuzzyListener.class })
public class ListenerDemo {
    @Test
    public void foo() {
        System.out.println("Hello world");
    }

    public static class MyFuzzyListener implements IReporter {

        @Override
        public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, final String outputDirectory) {
            Runtime.getRuntime().addShutdownHook(new Thread() {
                private File file = new File(outputDirectory + "/emailable-report.html");

                @Override
                public synchronized void start() {
                    boolean flag = false;
                    for (int i = 0; i < 10; i++) {
                        if (file.exists()) {
                            // Include your code here
                            System.out.println("Found the file @ " + file.getAbsolutePath());
                            flag = true;
                            break;
                        }
                        try {
                            Thread.sleep(1 * 1000 /* Sleep for a second */);
                            System.out.println("File is still not found. Slept for a second!");
                        } catch (InterruptedException e) {

                        }
                    }
                    if (! flag) {
                        System.out.println("Didn't find the file yet");
                    }

                }
            });
        }
    }

}


Disclaimer:
Since I am leveraging shutdownHooks here, this may not work fine if you abort your execution from an IDE such as eclipse!






Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/


Vinu Joseph

unread,
Jun 25, 2014, 5:48:38 AM6/25/14
to seleniu...@googlegroups.com
Hi all,
I am able to send automation mails using the maven-postman-plugin.
It sends a surefire report as an attachment.

This is the condition which i added in pom.xml so that the automation mail is sent always.

 <groupId>ch.fortysix</groupId>

    <artifactId>maven-postman-plugin</artifactId>

    <version>0.1.6</version>

    <configuration>

            <from>user...@gmail.com</from>

            <failonerror>true</failonerror>

                <mailhost>smtp.gmail.com</mailhost>

                <mailport>465</mailport>

                <mailuser>username@ gmail.com</mailuser>

                <mailpassword>************</mailpassword>

                <receivers>

                    <receiver>a...@gmail.com</receiver>

                    <receiver>1...@gmail.com</receiver>

                    <!--<receiver>some_anoth...@gmail.com</receiver> -->

                </receivers>

                <mailssl>false</mailssl>

                <mailAltConfig>true</mailAltConfig>  

                <groovyCondition><![CDATA[(errors>=0)||(failures>=0)]]></groovyCondition>

                

                

               <subject>Test Suite Status</subject>

            <htmlMessage>

                    <![CDATA[

                    <p>Here is the result of the test executions!</p>

                    <br>

                    <p>This is a test mail</p>

                    ]]>      

                </htmlMessage>              

                <fileSets>

                <fileSet>

                <directory>${project.build.directory}/site</directory>

                <includes>

                <include>**/surefire-report.html</include>

                </includes>

                </fileSet>

                </fileSets>

     </configuration>

</plugin>


Prasad Bodke

unread,
Aug 7, 2014, 4:20:31 AM8/7/14
to seleniu...@googlegroups.com
Hi Vinu,

I am not able to send mail with above given condition. How I can call postman plugin forcely.



Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:33.514s
[INFO] Finished at: Thu Aug 07 13:44:06 IST 2014
[INFO] Final Memory: 21M/52M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test (default-test) on project web-core-selenium: There are test failures.
[ERROR]
[ERROR] Please refer to D:\Project\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException


Thanks
Prasad




--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Prasad Bodke
9320675131

shas...@qapitol.com

unread,
May 9, 2017, 12:38:25 PM5/9/17
to Selenium Users
Hi All,

I'm able to send the report using javax.mail and javax.activation jars. But it sends the previous report not the latest one.
I'm calling the method to send mail from @AfterSuite section.
Can anyone help me out?

Here is my code.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public class SendMail {

//reportFileName = TestExecutionResultFileName
public static void execute(String reportFileName) throws Exception {
String path= System.getProperty("user.dir") + "\\test-output\\emailable-report.html";
String from = FilesAndFolders.getPropValue("emailFromUser");
String password = FilesAndFolders.getPropValue("emailFromPassword");
String to[] = getPropValues("emailTo");
String cc[] = getPropValues("emailCc");
String bcc[] = getPropValues("emailBcc");
String emailSubject = "This is subject";
String emailBody = FilesAndFolders.getPropValue("emailBody");
String host = "smtp.gmail.com";
String port = "465";
String attachmentPath = FilesAndFolders.getPropValue("emailAttachment");
reportFileName = reportFileName + ".html";

if(to.length==0){
System.out.println("No reciever email Id found");
return;
}


SendMail.sendMail(from,
password,
host,
port,
"true",
"true",
false,
"javax.net.ssl.SSLSocketFactory",
"false",
to,
cc,
bcc,
emailSubject,
"hello",
".\\test-output\\emailable-report.html",
reportFileName);
}

public static boolean sendMail(String userName,
String passWord,
String host,
String port,
String starttls,
String auth,
boolean debug,
String socketFactoryClass,
String fallback,
String[] to,
String[] cc,
String[] bcc,
String subject,
String text,
String attachmentPath,
String attachmentName){

//Object Instantiation of a properties file.
Properties props = new Properties();

props.put("mail.smtp.user", userName);

props.put("mail.smtp.host", host);

if(!"".equals(port)){
props.put("mail.smtp.port", port);
}

if(!"".equals(starttls)){
props.put("mail.smtp.starttls.enable",starttls);
props.put("mail.smtp.auth", auth);
}

if(debug){

props.put("mail.smtp.debug", "true");

}else{

props.put("mail.smtp.debug", "false");

}

if(!"".equals(port)){
props.put("mail.smtp.socketFactory.port", port);
}
if(!"".equals(socketFactoryClass)){
props.put("mail.smtp.socketFactory.class",socketFactoryClass);
}
if(!"".equals(fallback)){
props.put("mail.smtp.socketFactory.fallback", fallback);
}

try{

Session session = Session.getDefaultInstance(props, null);

session.setDebug(debug);

MimeMessage msg = new MimeMessage(session);

msg.setText(text);

msg.setSubject(subject);

Multipart multipart = new MimeMultipart();
MimeBodyPart messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(attachmentPath);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(attachmentName);
multipart.addBodyPart(messageBodyPart);

msg.setContent(multipart);
msg.setFrom(new InternetAddress(userName));

for(int i=0;i<to.length;i++){
msg.addRecipient(Message.RecipientType.TO, new
InternetAddress(to[i]));
}

for(int i=0;i<cc.length;i++){
msg.addRecipient(Message.RecipientType.CC, new
InternetAddress(cc[i]));
}

try{
for(int i=0;i<bcc.length;i++){
msg.addRecipient(Message.RecipientType.BCC, new
InternetAddress(bcc[i]));
}
}catch(NullPointerException e){}

msg.saveChanges();

Transport transport = session.getTransport("smtp");

transport.connect(host, userName, passWord);

transport.sendMessage(msg, msg.getAllRecipients());
transport.close();

return true;

} catch (Exception mex){
mex.printStackTrace();
return false;
}
}

//Get Multiple Prop values
public static String[] getPropValues(String key){
int totalCount = Integer.parseInt(FilesAndFolders.getPropValue(key + "TotalCount"));
if(totalCount==0){
return null;
}
String[] props = new String[totalCount];
for(int i=0;i<totalCount;i++){
props[i] = FilesAndFolders.getPropValue(key + i);
}
return props;
}
}

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

class TestClass {

@Test{
 public void test1(){
//Codes
}

@AfterSuite
public void sendMail(){
SendMail.execute(this.getClass().getSimpleName());
}
}

⇜Krishnan Mahadevan⇝

unread,
May 9, 2017, 12:42:57 PM5/9/17
to seleniu...@googlegroups.com

Do the following :

1  Move to the latest released version of TestNg
2. Build a listener that implements IExecutionListener
3. Incorporate your logic of sending mail via java code in this listener.
4. Wire in the listener using the listeners attribute in your suite xml.

Try again.


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--

Nikhil Mittal

unread,
May 23, 2019, 3:31:01 AM5/23/19
to Selenium Users
I tried these steps but no luck. The report is generated quite late. Is there any other suggestion ? All other stuff like AfterSuite, AfterClass,etc. does not work.
To unsubscribe from this group and stop receiving emails from it, send an email to seleniu...@googlegroups.com.

⇜Krishnan Mahadevan⇝

unread,
May 23, 2019, 10:21:34 AM5/23/19
to Selenium Users
Do you mind showing us what you tried ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages