Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

While running a test case, I have a try/catch mechanism and an onevent listener that produces a screenshot if an error/failure occurs. Can I also compose and email and attach that screenshot there and send it to someone?

share|improve this question
add comment (requires an account with 50 reputation)

3 Answers

up vote 5 down vote accepted

There is nothing to do with selenium here, You have to Check this link and override the attachment file with your Screenshot file.

share|improve this answer
there are some errors when I try to use that code.. – Jenny Kowalski yesterday
for example there is an object Session that asks me to create a class Session. What do I put in that class? – Jenny Kowalski yesterday
oh, I had to include some jars. thanks! – Jenny Kowalski yesterday
Glad, it helped you.! – Karthikeyan 21 hours ago
add comment (requires an account with 50 reputation)

This is more of a job for whatever is running your integration tests. Typically one runs integration tests on some kind of Continuous Integration environment, such as Jenkins. Your CI environment should support emails/notification of failing tests.

share|improve this answer
Yeah, but Jenkins is pain in the $$ for me and Java is so nice to work with... – Jenny Kowalski yesterday
Jenkins has some primitive email notifications, but I dont know how to make it attach a certain file (the one I just created) – Jenny Kowalski yesterday
add comment (requires an account with 50 reputation)

Yes. If you are using a linux box for executing your selenium test cases, you can install mutt, a CLI mail client to send mail with attachments. Also, there is JavaMail API that you can use. JavaMail API example

If you want to use mutt, first install mutt. Then create a file .muttrc in your home folder and include the following parameters for e.g:
set smtp_url = "smtp://[email protected]@smtp.gmail.com:587"
set smtp_pass = "password"
set realname = "Foo Bar"

Example:
mutt -s "test mail" [email protected] -a attachment.zip < email_body.txt

You need to include this command in a shell script and execute the script from a Java class using Runtime.getRuntime().exec(myShellScript);

share|improve this answer
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.