ReadyAPI is a powerful tool for quality assurance and functional testing. This guide demonstrates how to utilize MailSlurp's disposable email APIs in your Ready API tests to generate disposable mailboxes and receive email OTP verification codes for user sign up and confirmation.

Check out the full ReadyAPI example project on GitHub.

The problem

Say we are writing functional e2e tests of an application or API using ReadyAPI. We have an endpoint for user sign-up that expects an email address. This email must be unique and once submitted will receive an OTP verification code. Testing this process manually works but is slow and complex: we want to automate it using disposable and unique inboxes that can receive the MFA code. We then need a function to extract the confirmation code from the received email and submit it to confirm the user.

The solution

We can use the MailSlurp API definitions and import them into our ReadyAPI studio. These endpoints allow use to create email accounts on demand, receive emails, extract codes, and store those values in our test properties for further steps. All we need is a free API Key set as our Authorization JWT Bearer token.

Our end result will look something like this:

Step-by-step guide

Let's go over how to use email and SMS in ReadyAPI with example. In this test we will use MailSlurp's disposable inbox endpoints to create test email accounts and use them for testing a demo applications email sign-up and verification process.

Setup

  1. Create a new ReadyAPI project
  2. Import the MailSlurp API definition
  3. Create an environment with a base URL for MailSlurp: api.mailslurp.com
  4. Add an Authorization context with Auth JWT and set the Bearer token to your MailSlurp API Key

Authentication should be defined like so:

Writing the tests

The screenshot below shows the end test we will be creating.

The steps are the following:

1. Create inbox

Endpoint: mailSlurpApi Creates a fresh MailSlurp inbox to receive the verification/OTP email for the test run.

2. Store email address

Extract the generated inbox's emailAddress from the response and save it as a TestCase property, so later steps can reuse it.

3. Sign up in app

Endpoint: demoApplication Triggers the application's sign-up flow using the stored inbox email and a test password.

4. Wait for email

Endpoint: mailSlurpApi Polls MailSlurp until the verification email arrives. This waits for the latest email in the created inbox.

5. Store received email ID

Extract the received email's id and store it for use when retrieving or parsing the email content.

6. Extract confirmation code

Endpoint: mailSlurpApi Fetches the email content and applies a regex pattern to extract the OTP or verification code from the message body.

7. Store OTP code

Save the extracted OTP code as a TestCase property to be used in the confirmation step.

8. Confirm user

Endpoint: demoApplication Send the OTP code back to the application to complete the sign-up and confirm the user.

Finding the API definitions

Once we have added the aMailSlurp API to ReadyAPI as an API integration we can search through the available methods and select those that are needed for our test.

Storing values

During the test we need to pluck values from the MailSlurp API responses and store them in variables for use later in the test. This image shows how:

Next steps

To get started yourself, download the test project from GitHub and import it into ReadyAPI studio. For more information see the API Spec and developer docs.