Skip to main content

Automate email OTP verification using DevAssure

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

What is OTP?

OTP or One Time Password is used to secure data and a mechanism to secure user accounts through multi-factor authentication. Most applications have multi factor authentication enabled. In such applications, besides the username and password, users also provide the OTP, which is a series of alphanumeric characters generated at random for every request. Users also use OTP as a one-time access method to log in while validating the email they used to sign up.

One Time Password or OTPs change with every request made. And this is the reason it's difficult to create test automation for applications that are dependent on OTPs.

One of the most common delivery methods for OTPs is emails. As part of testing, we need to validate these emails for delivery and content. Additionally, we should also design the ability to retrieve the OTPs from these emails in test automation.

OTP Validation Test cases

If there are validations needed to be done specific to OTPs here are some of the test cases that can be considered for validations -

Consider a scenario where the applications Login requires OTP that is sent to the email of the user.

  1. Positive flow - Enter the email and generate OTP should trigger an email to the user's email id with the OTP. Entering the OTP should authenticate the user.
  2. Using an expired OTP should not authenticate the user on the application.
  3. Mismatched OTP - OTP generated for another email id cannot be used for the current email id
  4. Incorrect or blank OTP should not authenticate the user
  5. Generate 3 consecutive OTPs and validate only the most recent one authenticates the user

Note: These are just the basic cases. There could be more test scenarios depending on the feature or application under test.

Test automation helps speed up testing, specifically during regression testing. Automating test cases using OTP verification via emails, are quite challenging.

This involves -

  • connecting to the mail server,
  • logging in,
  • identifying the right email and
  • extracting the desired content from the email.

Key Challenges in Reading Email Content in Test Automation

  1. We cannot use the same email account for multiple test cases. If there are thousands of test cases to automate for an application, how many emails can you keep making?
  2. When many tests use the same email address, it can cause unreliable results. This is especially true when the tests run in parallel.
  3. The emails will keep piling up in one account and it will be hard to filter and find the right email for the test case. This can lead to flaky tests and unreliable test results.
  4. You need to rely on APIs or automate the processes to read content from the email address on the browser. This will also lead to flaky tests.

DevAssure's Low Code Platform for OTP Verification via Email

DevAssure simplifies email testing in test automation in 3 ways

  1. DevAssure provides the ability to create on demand email accounts while executing test automation.
  2. Every email account has an expiry date. No limit exists to how many email accounts you can create. We can provision a new email during every test execution.
  3. Using inbuilt libraries and actions, the email content can be accessible for validations or usage across the test cases.

WebApp Testing

DevAssure's capabilities in email testing will be explained using a demo web application for OTP login.

The first step would be to create a recording using DevAssure's intelligent recorder.

Here's a screenshot, post recording, that shows how DevAssure's low-code platform can be used to automate a test case. This includes email interactions and validations along with web app automation.

Email OTP Verification using DevAssure

Here's a detailed explanation of each of the steps in the no code platform:

Create new mail id

Using this action, you can create a new email account for the test case in your automation. Each time the test executes, a new email account will be created by DevAssure's in-built email server.

Create new mail id

You can manage these emails in DevAssure's Web Portal. Emails created via automation have an expiry date, which ensures ease of maintenance.

Managing email accounts in DevAssure's Web Portal

Wait for email

This action or keyword waits for the email to be delivered to the account created in the previous step. The maximum wait set is 10 seconds and this is configurable.

Wait for email

Get email text content

This action reads the email and gets the body of the email as textual content and saves it in a variable.

Get email text content

DevAssure's Advanced Code Block

DevAssure's advanced code block enables you to write your own custom libraries in javascript. This makes DevAssure one of the best no-code / low code test automation tools.

The script below, uses a regex expression to extract the OTP from the email content.

Advanced Code Block

Learn more about DevAssure's Advanced Code Block.

Input value

You can directly reference the values from the scripts or advanced code blocks, within the predefined actions.

Input value

Verification:

You can now validate the OTP and that the user has been able to log in.

Verification

Mobile App Testing

We will be using a sample mobile application to demonstrate DevAssure's capabilities in mobile app automation and email OTP verification.

Here's a screenshot of how DevAssure's low code platform can be used to automate email OTP verification in mobile applications. Email interactions and validations can be interleaved with the steps to test the mobile app.

Mobile app automation using DevAssure

Create new mail id

You can use this action to create a new email account for the test case in your automation. Every time the test is executed, a new email will be created at run time and be used for validations in automation.

Create new mail id

These emails can be easily managed and maintained in DevAssure's Web Portal.

Managing email accounts in DevAssure's Web Portal

Wait for email based on from address and subject

If there is a scenario where the same email account needs to be used for receiving and validating multiple emails within the same test case, filtering an email based on the address and subject proves to be effective and reliable.

Wait for email based on from address and subject

Get email text content

This action reads the email and gets the body of the email as textual content and saves it in a variable.

Get email text content

DevAssure's Advanced Code Block

DevAssure provides the ability to include custom scripts in javascript in your test automation using advanced code blocks.

The script below, uses a regular expression to extract the OTP from the email content.

Advanced Code Block

Learn more about DevAssure's Advanced Code Block.

Input value

The values from the scripts or advanced code blocks can be directly referenced to from within the predefined actions.

Input value

Conclusion

Email testing is always a challenge. Besides the ability to retrieve the data from the emails, DevAssure also provides the ability to validate the UX of the emails by rendering them in a browser.

View email in browser

This will additionally help validate the links, CTAs, images, text and any other content within the email using DevAssure's exhaustive list of actions and libraries available for validations.

Learn more about DevAssure's test actions here.

To experience how DevAssure simplifies test automation for email testing and OTP 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.