This example demonstrates use of MailSlurp with NodeJS, Webdriver.io (WDIO), Selenium and Chrome to test user processes that depend on email. It tests user sign-up and email confirmation using the MailSlurp OAuth2 Playground as a dummy login application (shown below).

login

About

Each test run does the following:

  • generates a real, randomized email address using MailSlurp
  • signs up with it in the browser
  • captures the email confirmation code with MailSlurp
  • enters in the confirmation code in the browser.

MailSlurp is free for personal use so sign up to run the example yourself.

Installing WebDriver and WDIO

In order to test a websites login process you need to load the website into a browser and performs some actions against it. We will use WDIO for this example: a Javascript library that automates browsers.

To install create a file and paste the following:

Then run

Configuring WDIO

Now add a file so we can configure WDIO to load the MailSlurp playground in the browser.

Write a test to sign up user

Configure MailSlurp

Create a test file called . Now let's configure MailSlurp:

Try loading the Playground

Our first test should load the playground and assert the sign-up form is present.

If we run the test with we should see passing tests.

login.

The first page to load is the login screen. As we want to sign-up let's click the link for that page in our test.

Create random email address and sign up

Now for the important part: creating a real email address on demand to sign-up a user with.

Notice how we created a new email address in each test run:

The inbox response object contains data like so:

The email address created is real and can receive emails sent from any application (including our login Playground).

Fetch confirmation email and verify account

Once the sign-up form has been submitted we can use MailSlurp to fetch the confirmation code and confirm the users account in the browser.

Notice the call to MailSlurp:

This call fetches the latest email in the given inbox or holds the connection open until the first email is received. This means the method will return the confirmation email sent by the Playground.

Can login with confirmed user

With our email address now confirmed lets log into the Playground and confirm we have access. A successful login should show a picture of a dog like so:

login.

Conclusion

MailSlurp lets you send and receive emails from randomly assigned email addresses. It's great for testing authentication flows with Webdriver, Cypress, Jest and more. It's free for personal use so sign up today!