Playwright is a powerful end-to-end integration testing framework created by Microsoft with support for multiple browsers and frameworks. It's a modern alternative to browser testing frameworks like Cypress and Selenium. Add MailSlurp to your test suite to test email login and verification with Playwright for full application testing using disposable email accounts.

Testing front-end login

In this example we will test a demo application called the Playground that allows user sign up with an email address and password. Upon signing up the user is sent a verification code that must be extracted from the email and entered into the confirm user form.

Setup (installing playwright)

The easiest way to get started is to use the methods in a new folder:

This will create a and an example test suite. The config for this example is as follows:

Install MailSlurp (email accounts)

Next we should install MailSlurp's free email library via NPM:

Create a free account and copy your API Key from the dashboard. We will need this for the next step.

Configure a test using the authentication playground

Let's write a test that signs up for an account on our test application called playground. We will create a new email address using MailSlurp, fill the login form and then receive an email verification code. We can extract the code from the disposable email account using MailSlurp and then submit the code to verify our address.

Writing the test

Playwright tests use a Jest-like structure and a page object to select elements on a page and wait for conditions.

Extracting the email verification code

The most import part of this test is using the disposable email account we created to receive a verification email and extract the code using a regex.

We can then enter the code into the verification form input and verify our user account.

Running the tests

To run the tests we can create a like so:

Then run the tests with . A successful login will show this friendly dog and a welcome message: