Skip to main content

Email Magic Link testing with DevAssure

· 5 min read
Divya Manohar
Co-Founder and CEO, DevAssure

Similar to OTPs, magic links are used to authenticate users by using only the email address. It is a "one-time use URL" sent to the user’s email address, which the user can use to securely access the application. The url contains time bound and secure embed tokens which help authenticate the user without a password.

Magic links can be used in the following scenarios -

  1. Multiple device access - Magic urls can be used to authenticate users across multiple devices. Each session can be authenticated with a unique magic link.
  2. Temporary access - Magic links are also used to provide temporary access to users.
  3. Account recovery or Password reset - Magic links can be used as a secure method for account recovery.

The user goes through 3 steps for applications using magic link -

  • The user enters the email address.
  • The user gets the magic link to their inbox.
  • The user clicks on the magic link, and is not able to securely login to the application.

How does a magic link work?

In order to test applications using magic links for authentication, the link needs to be retrieved from the email. This involves -

  1. Creating a mail id
  2. Connecting to the mail server
  3. Filtering the email of interest
  4. Retrieving the email content
  5. Identifying and getting the magic link from the email

Key Challenges involved in using emails in test automation

  1. The test automation tool should have the ability to create email accounts on-demand. Every test execution should have a new mail account created. Having the same email account for multiple test cases in test automation leads to the following issues -
    • Difficult to filter the specific email that corresponds to the test cases being executed. This will eventually lead to flaky tests.
    • When emails keep piling, filtering specific emails will lead to performance issues in test automation, thereby increasing the time of test execution.
    • Failed test retries will become challenging.
    • With more tests being executed, the number of emails in the single mailbox grows exponentially causing difficulty in maintenance.
  2. The test automation tool should have the ability to poll the email server to check if the email has been received. This should not be done by loading the inbox url in the browser and continuously refreshing and waiting until the email has been received. This will cause tests to be unstable.
  3. Integrating with 3rd party tools to manage emails, which requires writing and maintaining scripts and libraries.
  4. Parsing and validating the content of the email, subject line, from address and other parts of the email become challenging.

DevAssure is a unified, no code test automation platform that enables email testing without having to depend on 3rd party libraries and without having to consume any email APIs.

Here is a sample test automation script for a web application that authenticates users using a magic link.

The login page has a text box to enter the email address and a button clicking on which sends the magic link to the email address.

Sample automation

Explanation

DevAssure provides the ability to create new email addresses or mail ids for execution of the test automation script. The mail ids can be created using prefixes to be able to easily distinguish the ids created across different test cases.

Create new mail id

The mail ids created can also be accessed on DevAssure’s web portal. Additionally, these email accounts will automatically be managed and maintained by DevAssure.

Here is a list of actions that will be used on the app to trigger the magic link.

DevAssure Web Test Actions

Once the magic link request has been triggered, the next step is to wait for the email to be available. In this case, the DevAssure platform will poll the mail server at regular intervals for 10 seconds to check and retrieve the email.

Wait for email to be delivered

The following action helps get the email content.

Get email content

DevAssure provides the ability to write custom code as well depending on the application requirements. In this case, a regex can be used to retrieve the magic link from the email content.

Advanced code blocks

Learn more about Advanced Code Blocks.

The final step is to open the magic link and perform the validations to check if the user has been successfully authenticated.

Validation with DevAssure

To experience how DevAssure simplifies test automation for email testing and magic link verification, sign up for a free trial.


To explore how the DevAssure test automation platform can enhance your organization's testing capabilities, click the button below to request a personalized demo session with our team of experts.