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.
page.assignVarRemotelycommand, 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.
Let's open Puppetry, create a new project and navigate to Settings. There we define our template variables:
Signup flow 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.
Now we can define the test targets for the flow:
Signup flow targets
The registration form (see screenshot) has email, username, password, password confirmation inputs and submit button. We introduce these elements into Puppetry as
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
Signup test case, part 1
Next we use page.goto to navigate to the signup page.
We type in email address generated in
We type in username, dynamically built with faker expression.
We type in password and password confirmation by using
TEST_PASSWORDtemplate variable, which we defined above.
Finally we click on Submit button.
Signup test case, part 2
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
The we follow the link and make a new screenshot.
Now we can proceed with any of the following examples