Nightwatch is a powerful testing automation framework for testing web and native mobile applications. When combined with MailSlurp disposable test email accounts we can test real user authentication flows involving email verification and magic links.

In this example we will show you how to get started with Nightwatch and write tests for a demo application that permits user sign up and login with password-less email login powered by Firebase.

Get setup

Create a new NodeJS project and run the following:

Follow the prompts to configure end-to-end testing using a browser of your choice.

Next to create disposable temp email accounts we will use MailSlurp:

Make sure you get a free API KEY for the next steps.

Firebase authentication supports password-less email login providers. We will use a demo application that shows a login screen and allows users to access the site via password-less mail sign up. In this process the user enters their email address then Firebase emails them a link. When the link is clicked the user is taken to a logged-in session on the demo app. This authentication flow is quite typical for modern apps and can be tricky to test.

Testing email flows with Nightwatch

Luckily we can use Nightwatch and MailSlurp to write an automated end-to-end browser test for this scenario to test that user login and sign-up really works with our app.

Configure the tests

Create a new test file such as:

Add to it imports for Nightwatch and MailSlurp:

Next configure the MailSlurp client using your API KEY:

Load the site

The first step is to load the demo application. You can find the app on github or use the hosted version.

Create a temporary email address

Now we can create a throwaway email account using MailSlurp's createInbox method:

We use that to fill the email form and submit the login request.

Capture and read the email

Once submitted we expect Firebase to send a login link to our temporary email address. We can use MailSlurp's waitFor methods to wait until the email has arrived and return its content:

Let us check the content and expect a link:

We can use MailSlurp's built in link parser to find the embedded login link.

Now that we have received an email using our disposable mailbox we can load the link in the browser to simulate a user clicking it. This loads the signed-in session page on our demo app and proves our authentication flow is working as expected!

Conclusion

As you can see, testing email login processes is a great way to ensure that your application is functioning correctly. If you want to know that your site is really working then test with real email addresses and browsers. Nightwatch and MailSlurp are both free tools that enable you to test email processes at scale using automation.