Test user sign-up with NodeJS and WebDriver

Test email related processes like sign-up and verification using WDIO WebDriver and MailSlurp.

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



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 package.json file and paste the following:

  "scripts": {
    "test": "wdio wdio.conf.js"
  "dependencies": {
    "@wdio/cli": "^5.13.2",
    "@wdio/local-runner": "^5.13.2",
    "@wdio/mocha-framework": "^5.13.2",
    "@wdio/selenium-standalone-service": "^5.13.2",
    "@wdio/spec-reporter": "^5.13.2",
    "chromedriver": "^76.0.0",
    "mailslurp-client": "^6.5.0",
    "wdio-chromedriver-service": "^5.0.2"

Then run npm install

Configuring WDIO

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

const config = {
  runner: "local",
  path: "/",
  specs: ["test/*.test.js"],
  exclude: [],
  maxInstances: 10,
  capabilities: [
      maxInstances: 5,
      browserName: "chrome",
  logLevel: "info",
  bail: 0,
  baseUrl: "https://playground.mailslurp.com",
  waitforTimeout: 30000,
  connectionRetryTimeout: 90000,
  connectionRetryCount: 3,
  framework: "mocha",
  services: ["chromedriver"],
  reporters: ["spec"],
  mochaOpts: {
    ui: "bdd",
    timeout: 60000,

exports.config = config;

Write a test to sign up user

Configure MailSlurp

Create a test file called sign-up.test.js. Now let's configure MailSlurp:

const assert = require("assert");
const MailSlurp = require("mailslurp-client").default;
const apiKey = "your-api-key";
const mailslurp = new MailSlurp({ apiKey });

Try loading the Playground

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

describe("sign up process", () => {
  it("can load playground app", async () => {
    await browser.url("/");
    await browser.setWindowSize(1200, 1200);

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


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.

it("can load the sign-up section", async () => {
  // find the create account link and click it
  await $('[data-test="sign-in-create-account-link"]').then((e) => e.click());
  await $('[data-test="sign-up-header-section"]')
    .then((e) => e.getText())
    .then((text) => assert.strictEqual(text, "Testable Sign Up Form"));

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.

let inbox;
it("can sign-up with new user", async () => {
  // create a new email address for the test run
  inbox = await mailslurp.createInbox();

  // fill out and submit the new user form
  await $('[name="email"]').then((e) => e.setValue(inbox.emailAddress));
  await $('[name="password"]').then((e) => e.setValue(password));
  await $('[data-test="sign-up-create-account-button"]').then((e) => e.click());

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

inbox = await mailslurp.createInbox();

The inbox response object contains data like so:

  id: 'abc123',
  emailAddress: 'abc123@mailslurp.com'

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.

it("can fetch confirmation code", async () => {
  // fetch the email from mailslurp
  const email = await mailslurp.waitForLatestEmail(inbox.id);

  // verify that it contains the code
  assert.strictEqual(/verification code is/.test(email.body), true);

  // extract the confirmation code
  code = /([0-9]{6})$/.exec(email.body)[1];

it("can enter confirmation code and confirm user", async () => {
  await $('[name="code"]').then((e) => e.setValue(code));
  await $('[data-test="confirm-sign-up-confirm-button"]').then((e) =>

Notice the waitForLatestEmail call to MailSlurp:

const email = await mailslurp.waitForLatestEmail(inbox.id);

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:


it("can log in with confirmed account", async () => {
  // assert we see the sign in form
  await $('[data-test="sign-in-header-section"]')
    .then((e) => e.getText())
    .then((text) => assert.strictEqual(text, "Sign in to your account"));

  // fill out username (email) and password
  await $('[name="username"]').then((e) => e.setValue(inbox.emailAddress));
  await $('[name="password"]').then((e) => e.setValue(password));

  // submit
  await $('[data-test="sign-in-sign-in-button"]').then((e) => e.click());

it("shows the successful greeting", async () => {
  await $('[data-test="greetings-nav-bar"]')
    .then((e) => e.getText())
    .then((text) => assert.strictEqual(/Hello/.test(text), true));


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!

Related content

Golang email library for sending and reading emails

Golang Email Library for sending and receiving emails in Go over SMTP or HTTP/S.

NodeJS MailSlurp SDK

Nodemailer alternatives to send and receieve email in code and tests

Email for testing

Test email accounts for email testing. Alternatives to Mailinator, MailTrap, Mailosaur and more.

How to wait for Selenium to start during Codeception tests

Example tutorial for how to wait until webdriver and Selenium have started during Codeception PHP tests

Email API for email marketing and more

APIs for email marketing and social campaign testing. Send, receive, validate and test emails in code and online.

Fastest way to start a typescript project

Modern typescript tooling has come a long way. See how to setup a new project with TS-Node, TSC, and typeconfig.json.

Fetch error message javascript

Handle response exceptions with Fetch in Javascript

GraphQL API disposable email accounts

How to create real email addresses using GraphQL to send and receive emails in tests and frontend applications.

GraphQL Email API Tutorial

Did you know you can send and receive emails using GraphQL?

How to test an email address

Test email accounts for testing email addresses in code or online. Create fake email accounts for testing.

Hugo responsive image srcsets

Serve responsive picture tags with custom render-image layout partial in Hugo static site generator.

How to send emails in Javascript (NodeJS)

JS SMTP email sending guide using HTML and NodeJS.

NodeMailer NPM Tutorial

Send and receive email using NodeMailer in Node JS.

How to start selenium in a background process and wait for it to start

Spawn Selenium server process before tests start for easier acceptance testing.

Create custom print classes with Tailwind

Configure tailwind.config.js to create prefixed classes with a custom media query.

CypressJS Example

Test email sign-up. password verification and more with Cypress JS and MailSlurp.

CypressJS Email Testing

Use real email accounts in CypressJS to test user sign-up, email verification, and more.

Golang mail Library (SMTP)

How to send and receive emails in Go (test email addresses).

Java JVM Examples

Test email sending and receive emails without a mail server.

TestNG Selenium Java Example

Testing user sign up in Java using TestNG and MailSlurp test email accounts

Codeception PHP acceptance testing using real email address APIs

Write acceptance tests in PHP with real email addresses using Codeception and MailSlurp

PHP Email Test Plugins: send and receive email in PHPUnit (example code)

How to send and receive emails in PHPUnit tests.

PyTest Email Testing

Send and receive email in Pytest Python tests.

Java, Selenium

Receive emails in Java test suites using MailSlurp, Junit, and Selenium.

Receive email in PHP: using MailSlurp to send and receive emails

Test email in PHP using real email addresses

Python Robot Framework email test

Python automation email testing Robotframework plugin

Testing authentication using real email addresses in Ruby with Capybara, Cucumber, and Selenium

Cucumber example project using Capybara to test user authentication using real email addresses.

Send email with Axios JS (and receive email too!)

Send email in Javascript with MailSlurp email API

Test applications with real emails using Serenity BDD, JBehave and Selenium

Email acceptance testing with Serenity and MailSlurp. Test applications with real email addresses.

Specflow user sign-up testing with MailSlurp accounts

How to test .NET authentication and sign-up using real email accounts with MailSlurp and SpecFlow.

Jest, Puppeteer

Test email accounts in React with Jest and Puppeteer. Send and receive emails in Javascript.

.NET Selenium C#

Send and receive email in DotNET Nunit tests using Selenium and MailSlurp.

Cucumber, Ruby

Generate test email accounts with Ruby and Cucumber. Test email sign-up, password verification and more.

Webdriver, JS, WDIO

Test email related processes like sign-up and verification using WDIO WebDriver and MailSlurp.

TestCafe end-to-end MFA testing for user sign-up and email verification

End-to-end testing with MailSlurp, NodeJS, and TestCafe.

Base64 file uploads

How to encode files as Base 64 encoded strings in several languages

Deno Email Apis

Send and receive emails in Deno JS. Use APIs in Deno with MailSlurp.

Email read (opened seen settings)

How to control the seen or read settings for an email using MailSlurp.

How To Test Emails Before You Send

There are many free tools to test emails before sending. This can help prevent spam warnings and increase deliverability.

GraphQL Email API

Fetch and read emails with GraphQL inboxes using MailSlurp email API.

Testing OTP password link username and password for 2 factor authentication (2FA)

Testing OTP password link username and password for 2 factor authentication (2FA)

MailSlurp NodeMailer SMTP Usage

Use SMTP nodemailer with MailSlurp disposable email addresses

Test email address

Free test email address for testing emails online with web dashboard or REST API.

How to test 2FA OTP login using SMS codes with Playwright

The ultimate guide to testing OAuth one-time-password flows with real SMS MFA. Use Playwright to automate authentication tests with programmable TXT message APIs.

Testing guide

Integration testing with disposable email accounts using CypressJS, Selenium and many other frameworks. Test OTP password login, transactional emails, notifications and more.

Testing email with Cypress test email accounts

Test email accounts for CypressJS. End-to-end testing with real email addresses using MailSlurp Cypress plugin.

Testing Webhooks

How to test HTTP webhooks using MailSlurp test hooks.

Send emails in NodeJS using SMTP

How to use Javascript SMTP client (or Nodemailer) to send email with MailSlurp mail server

Testing Email with Cypress JS and MailSlurp

Email testing with Cypress JS

Ready to dive in?Start building email applications today.