Protractor E2E testing: email verification after creating an account Protractor E2E testing: email verification after creating an account selenium selenium

Protractor E2E testing: email verification after creating an account


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).


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.