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 name | Return type |
---|---|
attachments | AttachmentCollection |
from | EmailAddress |
to | EmailAddressCollection |
subject | string |
date (time sent) | Date |
received_date | Date |
message_id | string |
headers | InternetMessageHeaderCollection |
html | |
text | string |
mail_from | EmailAddress |
rcpt_to | EmailAddressCollection |
size | number |
projectId | string |
string | |
expire_at | string |
created_at | string |
updated_at | string |
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:
- On the left menu, click on the Settings icon.

- Click the Email Service tab.

- Click the Generate Email Address button.

- 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:
- Hover over the (arrow symbol) where you want to add the step.
The action options are displayed.
- Click on the “M” (Testim predefined steps).
The Predefined steps menu opens.
- Click on Validations.
The Validations menu expands.
- 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.
- In the Name the new step field, enter a (meaningful) name for this step.
- 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. - Click Create Step.
The function editor opens, and the Properties panel opens on the right-hand side.

- Copy the permanent email address and paste it into the Email address field. This email address should be surrounded by single or double quotes.

- Set additional settings in the step and parameters as needed.
- 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>)
.
- 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:
- Hover over the (arrow symbol) where you want to add the step.
The action options are displayed.
- Click on the “M” (Testim predefined steps).
The Predefined steps menu opens.
- Click on Actions.
The Actions menu expands.
- 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.
- Hover over the newly created step, and click on the Show Properties () icon.
The Properties panel opens on the right-hand side.
- In the Variable name field, enter name for the variable that will hold the temporary email address. For example, use the value
emailAddress
. - In the Variable scope field, specify the scope in which the variable can be passed:
- Local: Allows you to pass the emailAddress parameter between steps in the same scope. This is the default.
- Test: Allows you to pass the emailAddress parameter between steps and groups in the same test.
- Suite: Allows you to pass the emailAddress parameter between tests in the same test suite.
- Set additional settings in the step and parameters as needed.
- 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:
- Hover over the (arrow symbol) where you want to add the step.
The action options are displayed. - Click on the “M” (Testim predefined steps).
The Predefined steps menu opens. - Click on Validations.
The Validations menu expands. - 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.
- In the Name the new step field, enter a (meaningful) name for this step.
- 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. - Click Create Step.
The function editor opens, and the Properties panel opens on the right-hand side.

- 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] - Set additional settings in the step and parameters as needed.
- 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>)
.
- 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
Updated about 2 months ago