Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor E2E testing: email verification after creating an account

So I am writing some E2E tests for creating an account on a website. After creating a website account, the website will send me an email to verify my account so I can login. My question is, how far is E2E testing suppose to go? would I be going in the wrong direction if I use protractor to go to google, find the email, and click the link to verify myself. Then go back to the website and login? My other possible option would be to somehow get my userID and then send a request for verification?

I'm just not sure which direction would be best. Any ideas?

like image 790
Frank Avatar asked Feb 19 '15 19:02

Frank


Video Answer


2 Answers

It is pretty much arguable how far your tests should go. But if there is a critical to testing information being sent on email, you should consider extracting that information during the test run.

In other words, this is so called "end-to-end testing", but both of the ends could be beyond the borders we are used to think and consider.

Here is the solution using mail-listener2 nodejs library that worked for me during the Two Factor Authentication functionality test (registration code is sent to an email after passing username/password verification step).

like image 109
alecxe Avatar answered Sep 27 '22 18:09

alecxe


Personally I do test that a verification email gets sent with the correct contents — I do not, however, login at Google, to find the email. Instead I've exposed a server side function that returns the latest email it sent to a certain email address. Here's how I use it:

b.get(origin + '/-/e2e/last-email-sent?to=' + address, (response) => {
  var responseObj = JSON.parse(response.body);
  // Now I have the email text in responseObj.bodyHtmlText.
  // Let's extract the URL to the next page:
  // (it's the first thing we find that starts with our server origin, i.e.
  // http://whatever/....)
  var regexString = originRegexEscaped + '\\/[^"]+';
  var matches = responseObj.bodyHtmlText.match(new RegExp(regexString));
  if (!matches) {
    b.assert.fail(responseObj.bodyHtmlText, regexString,
      'No next-page-link regex match in email');
  }
  else {
    // Tell our e2e browser to go to the page linked in the email
    // as if the user had clicked the link in the email.
    b.url(matches[0]);
  }
});

I'm going to add lots of other funny e2e test server side functions too, like /-/e2e/fast-forward-time?how-much=3600-seconds :-)

What I do test, with a real Gmail user (a real Gmail account I created for e2e tests and nothing else), is just signups. I.e. that OpenAuth login works. If that works, I'm going to assume any Gmail user is thereafter able to read emails.

like image 20
KajMagnus Avatar answered Sep 27 '22 18:09

KajMagnus