Search
 
 

Display results as :
 


Rechercher Advanced Search

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Automate sending an email in Selenium IDE

View previous topic View next topic Go down

Automate sending an email in Selenium IDE

Post by rodale_janet on Fri Mar 07, 2014 10:49 pm

Can you send an email with the results file attached from Selenium itself or do you need to do it another way.  I have VBS code that I can modify to send an email with an attachment just do not know how to get it to execute.   Thanks!!

rodale_janet
Active particpant
Active particpant

Posts : 10
Join date : 2014-03-07

Back to top Go down

Re: Automate sending an email in Selenium IDE

Post by Adviser on Tue Jun 24, 2014 5:26 pm

HI,
 you can do it in 2 ways:

1. write the same logic of VBscript in your selenium scripting language.
2. find a way to execute a .vbs or batch file via selenium programming.

choose the either way to get a solution. google it for exact snippet.

_________________
Spread Your Knowledge About Selenium Tool.

Administrator
Email: selenium.discussion.thread@live.com
Forum: http://seleniumforum.forumotion.net

Adviser
------------------------
------------------------

Posts : 379
Join date : 2009-07-30
Location : India

http://seleniumforum.forumotion.net

Back to top Go down

Re: Automate sending an email in Selenium IDE

Post by rodale_janet on Tue Jun 24, 2014 7:09 pm

Thanks!!

I actually found something on the internet that supplied code to do it in Java.   I have a "SendMail" class that I execute if there is an error or if the test completes successfully.

rodale_janet
Active particpant
Active particpant

Posts : 10
Join date : 2014-03-07

Back to top Go down

Re: Automate sending an email in Selenium IDE

Post by saravana.s on Fri Jun 27, 2014 6:28 pm

Thanks for sharing good information. Keep posting

saravana.s

Posts : 2
Join date : 2014-06-27

Back to top Go down

Re: Automate sending an email in Selenium IDE

Post by rodale_janet on Fri Jun 27, 2014 6:36 pm

Code:
Here is the code that I found and am using.  You need to bring in the JavaMail library to your project.:
package [name of your package];

import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.activation.*;

public class SendMail {
   public SendMail(String[] toMail, String subject, String msg) {
          Properties props = System.getProperties();
          props.put("mail.smtp.host", "smtp.rodale.com");
          props.put("mail.smtp.port", "25");
          Session session = Session.getDefaultInstance(props);
          try {
              Message message = new MimeMessage(session);
              message.setFrom(new InternetAddress("TestAutomation@rodale.com"));
              InternetAddress[] toAddress = new InternetAddress[toMail.length];

              for( int i = 0; i < toMail.length; i++ ) {
                   toAddress[i] = new InternetAddress(toMail[i]);
               }

               for( int i = 0; i < toAddress.length; i++) {
                   message.addRecipient(Message.RecipientType.TO, toAddress[i]);
               }

              message.setSubject(subject);
              message.setText(msg);
              Transport.send(message);
              System.out.println("Done");
          }
          catch (MessagingException ex) {
              throw new RuntimeException(ex);
          }
         
   }

}

This is how my code uses it:
private void executeSubXpath (String urlName, String menuItem, String pageTitle)
   {
      String msg = "";
                  
      wait_fiveSeconds();
      try
       {
          WebElement subElement = driver.findElement(By.id(menuItem));
          String urlLink = subElement.getAttribute("href");
          JavascriptExecutor js = (JavascriptExecutor) driver;
         
            
          System.out.println(urlLink);
         wait_fiveSeconds();
         js.executeScript("arguments[0].setAttribute('target', arguments[1]);", subElement, "_self");
         js.executeScript("arguments[0].click();", subElement);
           wait_fiveSeconds();
          checkUrl(urlName, pageTitle, urlLink);
       }
      
       catch (Exception e)
       {
          System.out.println(e);
          msg = urlName + " test was not successful" +
                System.getProperty("line.separator") + System.getProperty("line.separator") + e;
          new SendMail(to_email,urlName,msg);
          errorsFound = true;
          driver.navigate().to(baseUrl);
       }
       wait_fiveSeconds();
   }

rodale_janet
Active particpant
Active particpant

Posts : 10
Join date : 2014-03-07

Back to top Go down

Re: Automate sending an email in Selenium IDE

Post by Sponsored content Today at 3:13 pm


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum