- rodale_janetActive particpant
- Posts : 10
Join date : 2014-03-07
Automate sending an email in Selenium IDE
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!!
Re: Automate sending an email in Selenium IDE
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.
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.
- rodale_janetActive particpant
- Posts : 10
Join date : 2014-03-07
Re: Automate sending an email in Selenium IDE
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.
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.
- saravana.s
- Posts : 2
Join date : 2014-06-27
Re: Automate sending an email in Selenium IDE
Fri Jun 27, 2014 6:28 pm
Thanks for sharing good information. Keep posting
- rodale_janetActive particpant
- Posts : 10
Join date : 2014-03-07
Re: Automate sending an email in Selenium IDE
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();
}
Permissions in this forum:
You cannot reply to topics in this forum