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?
3 Answers
There is nothing to do with selenium here, You have to Check this link and override the attachment file with your Screenshot file.

- 1
- 1

- 2,634
- 5
- 30
- 51
-
for example there is an object Session that asks me to create a class Session. What do I put in that class? – Kaloyan Roussev Aug 06 '13 at 13:05
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.

- 18,217
- 6
- 44
- 80
-
Jenkins has some primitive email notifications, but I dont know how to make it attach a certain file (the one I just created) – Kaloyan Roussev Aug 06 '13 at 13:01
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://your_id@domain.com@smtp.gmail.com:587"
set smtp_pass = "password"
set realname = "Foo Bar"
Example:
mutt -s "test mail" your_id@domain.com -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);

- 3,770
- 29
- 41

- 1,578
- 4
- 27
- 50