8

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?

Frank
  • 215
  • 3
  • 9
  • In my personal situation I had the same dilemma. My route to solve it was to (as you mentioned) use the userId to do the verification process via HTTP. – Aaron Feb 19 '15 at 19:28
  • I was literally going to ask the same question today :) – alecxe Feb 19 '15 at 19:37
  • lol I guess i beat ya to it @alecxe ;D. – Frank Feb 19 '15 at 20:17
  • Thanks for the input @Aaron I'm going to try this route I think. How were you able to get your userID? Was it something that had to be echoed back to you after creating an account? If this is the case I was thinking about just echoing the whole link to myself. Then take the link and just put it in my URL address bar. – Frank Feb 19 '15 at 20:17
  • @FrankInsana Yea, I echoed back user information, and then used the userID to go through my authentication process automatically. Right now I have a script that runs at the start of most of my test suites that creates/verifies a user without even clicking through the UI to do so. – Aaron Feb 19 '15 at 20:22
  • Hey @Aaron actually I have another question for you if you don't mind. So I have 2 test suites set up. One of them creates the account (Test_Signup) and the other one logs in the account(test_login). The userID is echoed to me in Test_Signup. Do you know if there is a way to pass that userID to the next test suite (test_login)? So far I can't find a way to pass the userID over to other test suites. After some reading I found something saying that doing something like this is bad. My other option would be to maybe create another test suite that somewhat combines the two already made test suites – Frank Feb 20 '15 at 01:18
  • @Frank I have a module where I have a "create user" script that handles my user creation/verification process. I clear the database I'm working with after each suite runs - so I run the "create user" script at the start of each suite. Each one of my suites is a scenario a user might go through, so I have my tests designed to run completely decoupled from one another. – Aaron Feb 20 '15 at 14:04
  • hey @Aaron do you mind posting your module? I also have another question that I posted and I feel like you could answer it if you don't mind. http://stackoverflow.com/questions/28727854/using-data-objects-while-e2e-testing-with-protractor?noredirect=1#comment45745387_28727854 – Frank Feb 25 '15 at 22:41
  • I am trying to do what you did, but I feel like I have more questions after I started to code it all out – Frank Feb 25 '15 at 22:42
  • @Frank yea I'll post an answer tonight based off what I'm currently doing. – Aaron Feb 26 '15 at 19:19
  • You can listen for an email in your tests, here is [the solution](http://stackoverflow.com/a/29382990/771848) that worked for me. – alecxe Apr 01 '15 at 04:49

2 Answers2

4

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

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
1

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.

KajMagnus
  • 11,308
  • 15
  • 79
  • 127