3

I'm looking to use CasperJS/PhantomJS to automate the testing of a project that extensively uses email as part of its process but I keep running into issues when I need check the content of emails in an automated way.

These tools are very capable of crawling through the HTTP version of many email services, but maintaining tests to keep up with UI changes made to external services is not something I want to do.

Do CasperJS or PhantomJS have the ability to use IMAP or POP3 to retrieve mail, or is there a more common solution that is generally implemented?

Citricguy
  • 412
  • 7
  • 21
  • Did you get something working in the end? If so, which packages/approach did you use? – Darren Cook Jun 21 '14 at 06:56
  • I ended up doing what I was trying to avoid. I configured CasperJS to automate the clicking of links using a webmail app. Not very sexy, but it works very well. – Citricguy Jun 21 '14 at 07:59
  • Which webmail service did you end up using? Gmail appears to be the worst option between the minimized class and id names and random modals. Thanks. – bikedorkseattle Aug 18 '14 at 21:54
  • I ended up using the RackSpace email service. GMail worked as well, but like you mentioned, it was a nightmare to configure originally. Try using the HTML version of gmail to simplify things for sure. https://mail.google.com/?ui=html – Citricguy Aug 19 '14 at 01:21

4 Answers4

2

You can use any nodejs module with Casper:

"Like PhantomJS, CasperJS allows using nodejs modules installed through npm."

So you just need to check the npm repo and test which lib suits you.

Jakub Kania
  • 15,665
  • 2
  • 37
  • 47
  • But... these modules still run in the PhantomJS environment, right? So do you have access to the core Node modules that these email-handling modules undoubtedly use? – nrabinowitz Apr 02 '14 at 16:23
  • Are they any tutorials, or blog posts, that show how to do this? (Even just knowing someone managed it, and which of those many packages they went with, would be very helpful.) – Darren Cook Jun 20 '14 at 21:35
  • @DarrenCook Not that I know of, I haven't personally tried it. Probably Citricguy will know. – Jakub Kania Jun 20 '14 at 21:57
2

Hi using casperjs\Phantomjs you can navigate and automate however for mailing process you have to use nodejs nodemailer module.Try the following command after installing nodejs.

npm install nodemailer@0.7.1.

This installs the nodemailer package and post that you can install the mail clients like sendgrid sendmail or you can just use the nodemailer direct transport but that may cause some delay in mail delivery.

Kindly check the nodemailer scripts and run the script using: node scriptname.js

1

PhantomJS (and by extension, Casper) is a web browser - it's not able to use POP or IMAP as far as I know. My first thought as to approach would be to use a separate system for test automation (at least, for those tests that require verifying emails), e.g. using Python, Ruby, or Node.js, invoke Casper via the command line within those tests, and then use a separate tool to check and verify the email.

nrabinowitz
  • 55,314
  • 10
  • 149
  • 165
  • PhantomJS is a browser but CasperJS is a testing utility. Sometimes the best tools are those we already have and although a seperate system sounds better it may not be worth the price. – Jakub Kania Apr 02 '14 at 12:47
1

You could also use a dev smtp server with a web interface like mailcatcher (ruby) or maildev (node).

They also have a rest api, which returns the email in a more stable way than to use the web interface.

I don't tested it, but will soon.

yvess
  • 1,992
  • 19
  • 17