Testing Transactional Emails

Transactional email is a sort of email that require an action from the receiver side like in signup confirmation emails, password resets, purchase notifications and others. In order to automate testing of user flows involving transactional emails we need to be able to request the inbox contents from the testing tool. That can be achieved by using an email server with REST API or a specialized service such as Sendgrid, Mailgun, Email Yak, Postmark. These services are normally quite expensive, so alternatively we can develop a bridge one, which uses IMAP or, let’s say, Google API to access a public email server. Just to give it a try we can even go with Restmail.net, which is free and requires no registration or set up.

Puppetry provides page.assignVarRemotely command, which polls a given email server REST API until the desired email received (ot timeout). It retrieves the parsed the parsed value (e.g. activation link) and assigns it to a dynamic template variable accessible in all following test steps. The command can be configured to parse the received content.

Testing Signup Flow

To get a better grip on the idea we are going to create a simplified test project for imaginary ACME forum built with NodeBB. So the test scenario would be to type in required fields on the registration form, submit the form and use the link sent by email to activate the account.

Template Variables

Let's open Puppetry, create a new project and navigate to Settings. There we define our template variables:

What we need are BASE_URL (http://localhost:4567/ NodeBB default one for development environment), which depends on testing environment and TEST_PASSWORD (fixture password used for registration) that once defined we can reuse across the project.

Test Targets

Now we can define the test targets for the flow:

The registration form (see screenshot) has email, username, password, password confirmation inputs and submit button. We introduce these elements into Puppetry as REG_EMAIL_INPUT, REG_USERNAME_INPUT, REG_PASSWORD_INPUT, REG_CON_PASSWORD_INPUT, REG_SUBMIT_BTN. After submitting the form the application brings us to the GDPR form (see screenshot), where we need to tick on consent checkboxes and click on Register button. Those elements we refer as REG_AGREE_EMAIL_CHECKBOX, REG_AGREE_DATA_CHECKBOX, REG_REGISTER_BTN.

Test Case

First we need to ensure that we do no register an existing user. So we need to use a unique email address. That we achieve by dynamically assigning a template variable TEST_EMAIL that will accept during test run iterating values like test1@acme.com, test2@acme.com and so on.

Next we use page.goto to navigate to the signup page.

We type in email address generated in TEST_EMAIL.

We type in username, dynamically built with faker expression.

We type in password and password confirmation by using TEST_PASSWORD template variable, which we defined above.

Finally we click on Submit button.

That is supposed to bring us to the next page with the GDPR form.

So we wait until the page is ready

We make a screenshot.

We tick on the consent checkboxes.

We click on Register button.

We wait until the sent email arrives to the inbox and assign the parsed activation link to template variable ACTIVATION_LINK.

The we follow the link and make a new screenshot.

Remote Service

Now we can proceed with any of the following examples

pageExample with Restmail.netpageExample with MailinatorpageExample with IMAP bridgepageExample with Google API

Last updated