Validate email

Validate sign-up and login flows

Testim offers a built-in email service which provides permanent and temporary email addresses. The Validate email step can be used to validate that an email was sent to these email addresses. This step is typically used to test your app sign-up or login flows.

πŸ“˜

This is a pro feature only open to projects on our professional plan. To learn more about our professional plan, click here.

The Validate email step is a predefined validation step that receives your Testim inbox content of a specified Testim email address as an array of all of the messages within that mailbox, contained in a parameter named messages with the following fields:

Field nameReturn type
attachmentsAttachmentCollection
fromEmailAddress
toEmailAddressCollection
subjectstring
date (time sent)Date
received_dateDate
message_idstring
headersInternetMessageHeaderCollection
html
textstring
mail_fromEmailAddress
rcpt_toEmailAddressCollection
sizenumber
projectIdstring
emailstring
expire_atstring
created_atstring
updated_atstring

There are two ways to validate emails, each way differs in the flow and is explained separately below:

  • Permanent email method - Testim offers a permanent email address that you can use for many purposes, including testing login flows and password reset flows. As part of the test, you will be able to validate that emails are sent to the email address, by adding this email address to the Validate Email step. This step will include code that will validate that the email was received in the permanent email address, for example, by fetching a link from the email and exporting it.
  • Temporary email method - There are times you may need to generate a new random email address every time you run a test, for example to test a sign-up flow multiple times with a new user each time. Using the Generate email address step, a new email address is generated with every run. You will configure the Generate email address step to save the temporary email address as a parameter. And then you will be able to validate that emails are sent to the temporary email address, by adding this parameter to the Validate Email step. The Validate Email step will include code that will validate that the email was received in the permanent email address, for example, by fetching a link from the email and exporting it.

Permanent email method

The process assumes that you have an existing or new test that will include the Validate email step.

Step 1 - create a permanent email

To create a permanent email:

  1. On the left menu, click on the Settings icon.
  1. Click the Email Service tab.
  1. Click the Generate Email Address button.
  1. A random email address is generated and shown on the page. Hover your mouse over the email address and click Copy, to copy the email address or Inbox to view the email's inbox.

Step 2 - Use the permanent email in the relevant steps of the test

This email address can be used as an input in the test. For example, a test that validates the sign up process, in which the user enters an email and password and then receives an email with a link that should be clicked in order to confirm/validate the email. In this example, the permanent email address will be used in the sign up step, where the user enters the email address.

In the example below, the permanent email address was entered to the Text to assign field of the Set text step, where the user enters the email address into the email field.

Step 3 - Create a "Validate email" step

As part of this test we want to check that the sign up confirmation email was sent to the permanent email, by adding a Validate email step. In our example, the step will include a code that checks the permanent email inbox and if there is an email, it will export the link from this email.

To create the validate email step:

  1. Hover over the (arrow symbol) where you want to add the step.

The action options are displayed.

  1. Click on the β€œM” (Testim predefined steps).
    The Predefined steps menu opens.

  1. Click on Validations.
    The Validations menu expands.

  1. Scroll down through the menu and select Validate email.

πŸ“˜

Alternatively, you can use the search box at the top of the menu to search for Validate email.

The Add Step window is shown.

  1. In the Name the new step field, enter a (meaningful) name for this step.
  2. If this is a shared step to be made available to reuse in this or other tests, keep the box next to Shared step selected (default), and choose a folder from the Select shared step folder list where you want this step stored. Otherwise, deselect the checkbox.
    For more information about shared steps, see Groups.
  3. Click Create Step.
    The function editor opens, and the Properties panel opens on the right-hand side.
  1. Copy the permanent email address and paste it into the Email address field. This email address should be surrounded by single or double quotes.
  1. Set additional settings in the step and parameters as needed.
  2. In the function text box, type in the desired JavaScript code. If you have defined parameters, you can refer to those parameters in your JavaScript code. See the Email validation examples section below to learn about different ways to validate the email. The code will typically use value entered into the Email address field as a parameter in the code.

πŸ“˜

If you are using DOM selectors other than HTML parameters (e.g. jQuery), then empty arrays are truthy, so you need to use $(<query>).length instead of $(<query>).

  1. Click the back arrow to return to the main Editor window.

πŸ“˜

If you opened your AUT to define an HTML element as a parameter, click on the Toggle Breakpoint button to remove the breakpoint.

The step is created.

Temporary email method

The process assumes that you have an existing or new test that will include the Generate email address and the Validate email steps.

Step 1 - Add the Generate Email Address step

In this step we will add the step that will generate the temporary email address and save the address as a variable to be used in other steps.

To generate a temporary email address:

  1. Hover over the (arrow symbol) where you want to add the step.

The action options are displayed.

  1. Click on the β€œM” (Testim predefined steps).
    The Predefined steps menu opens.

  1. Click on Actions.
    The Actions menu expands.

  1. Scroll down through the menu and select Generate email address.

πŸ“˜

Alternatively, you can use the search box at the top of the menu to search for Generate email address.

A β€œGenerate email address” step is added in the Editor.

  1. Hover over the newly created step, and click on the Show Properties () icon.

The Properties panel opens on the right-hand side.

  1. In the Variable name field, enter name for the variable that will hold the temporary email address. For example, use the value emailAddress.
  2. In the Variable scope field, specify the scope in which the variable can be passed:
    1. Local: Allows you to pass the emailAddress parameter between steps in the same scope. This is the default.
    2. Test: Allows you to pass the emailAddress parameter between steps and groups in the same test.
    3. Suite: Allows you to pass the emailAddress parameter between tests in the same test suite.
  3. Set additional settings in the step and parameters as needed.
  4. Copy the parameter name in the variable name field. (e.g. the name emailAddress)- This parameter will be used in the Email Validation step.

Step 2 - Create a "Validate email" step

As part of this test we want to check that the sign up confirmation email was sent to the temporary email by adding a Validate email step. In our example, the step will include a code that will check that the temporary email, which is stored in the emailAddress parameter, includes an email and if there is an email, it will export the link from this email.

To create the validate email step:

  1. Hover over the (arrow symbol) where you want to add the step.
    The action options are displayed.
  2. Click on the β€œM” (Testim predefined steps).
    The Predefined steps menu opens.
  3. Click on Validations.
    The Validations menu expands.
  4. Scroll down through the menu and select Validate email.

πŸ“˜

Alternatively, you can use the search box at the top of the menu to search for Validate email.

The Add Step window is shown.

  1. In the Name the new step field, enter a (meaningful) name for this step.
  2. If this is a shared step to be made available to reuse in this or other tests, keep the box next to Shared step selected (default), and choose a folder from the Select shared step folder list where you want this step stored. Otherwise, deselect the checkbox.
    For more information about shared steps, see Groups.
  3. Click Create Step.
    The function editor opens, and the Properties panel opens on the right-hand side.
  1. Enter the name of the Variable name parameter, which you defined in the Generate email address step, into the Email address field.
    [block:image]
    {
    "images": [
    {
    "image": [
    "https://files.readme.io/3bfe619-image.png",
    null,
    null
    ],
    "align": "center"
    }
    ]
    }
    [/block]
  2. Set additional settings in the step and parameters as needed.
  3. In the function text box, type in the desired JavaScript code. If you have defined parameters, you can refer to those parameters in your JavaScript code. See the Email validation examples section below to learn about different ways to validate the email. The code will typically use value entered into the Email address field as a parameter in the code.

πŸ“˜

If you are using DOM selectors other than HTML parameters (e.g. jQuery), then empty arrays are truthy, so you need to use $(<query>).length instead of $(<query>).

  1. Click the back arrow to return to the main Editor window.

πŸ“˜

If you opened your AUT to define an HTML element as a parameter, click on the Toggle Breakpoint button to remove the breakpoint.

The step is created.

Email validation examples

Validate sign-up subject line

You can use the Validate email step to validate the contents of the subject line of an email generated by your app that was sent to a Testim-generated email address.

Example Code:

if (messages && messages[0] ){
  return messages[0].subject === "Thank you for signing up";
}
return false;

Validate links in body

You can use the Validate email step to look for hyperlinks in the body of an email, and return the text component and link component of each link found.

Example Code:

if (!messages && !messages[0]){
  throw new Error("Failed to find message in inbox ");
}
function getLinks(html) {
   var parser = new DOMParser();
   var doc = parser.parseFromString(html, "text/html");
   var linksElements =  Array.from(doc.querySelectorAll("a"));
  return linksElements.map(linkElement => ({text:linkElement.innerText,link:linkElement.getAttribute("href")}));
}
var emailLinks = getLinks(messages[0].html);
exportsTest.emailLink = emailLinks[0]; //exports the first link in the array to the next test steps