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.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.
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.
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.
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_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
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 [email protected], [email protected] and so on.
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_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
The we follow the link and make a new screenshot.
Now we can proceed with any of the following examples