MailSlurp logo

Testing email OTP in UIPath Studio

Use programmable email accounts in UI Path integration testing for MFA/2FA verification

Use with your tools

Your UiPath test has filled out the signup form and reached the verification screen. Now it needs the code from the email, just as a customer would. UiPath Studio can combine browser actions with HTTP requests to fetch that message and finish signup.

Copying a code from your own inbox works for a quick check, but an automated run needs its own address and a way to read the current message. With MailSlurp's programmatic email testing, the workflow can create an inbox, wait for the application's email and enter the delivered code.

The complete source code is available on GitHub.

Tutorial

Let's build that flow with the MailSlurp Playground application. The video follows the same sequence: create an inbox, sign up, receive the code and check the verified account.

MailSlurp video Open video on YouTube

What is OTP?

An OTP, or one-time password, is a temporary code used to verify an account action. In this email OTP verification example, the application sends the code to the address entered during signup.

The test needs the code from this signup attempt, and it must submit it while the application still accepts it. After verification, we'll sign in and check the account. That catches a failure a simple "email received" assertion would miss.

How to test verification in UiPath

Assuming you already have UiPath Studio installed on your Windows PC, we can use the program to define a series of steps and automations that will:

  • Load a demo web application in Chrome
  • Create a new user email account using MailSlurp HTTP requests
  • Use browser automation to fill out a user sign-up form
  • Wait for and extract the OTP code using MailSlurp
  • Submit the OTP code using Chrome automation and then assert user is verified

Our end workflow will look something like this:

UiPath disposable email accounts using MailSlurp for OTP end-to-end testing. UiPath disposable email accounts using MailSlurp for OTP end-to-end testing.

Setup

First you need a free MailSlurp account. You can create a free account and obtain an API Key. We will use this in the next steps.

Step 1: Load the demo web application in Chrome

Start by opening the MailSlurp playground application in Chrome using UiPath browser automation. This demo app simulates a real user sign-up and email verification flow.

In UiPath Studio, create a new Process and add a Use Application/Browser activity. Select Chrome as the browser and set the URL to: https://playground.mailslurp.com

Once the page loads, add a Check App State or Element Exists activity to confirm the application is ready. Target a stable element such as the page header or the sign-up button to avoid flaky tests.

Step 2: Create a new user email account using MailSlurp HTTP requests

Next, create a disposable email inbox using the MailSlurp API. This inbox will receive the OTP verification email during sign-up.

Add an HTTP Request activity with the following configuration:

  • Method: POST
  • URL: https://api.mailslurp.com/inboxes
  • Headers:
    • x-api-key: YOUR_API_KEY
    • Content-Type: application/json
    • Accept: application/json

Store the response body in a string variable. Use regular expressions to extract the inbox ID and email address from the JSON response.

  • Inbox ID regex: "id"\s*:\s*"([^"]+)"
  • Email address regex: "emailAddress"\s*:\s*"([^"]+)"

Save these values to variables named inboxId and emailAddress.

Step 3: Fill out the user sign-up form using browser automation

With a real email address available, automate the sign-up flow in the browser.

Using Chrome automation in UiPath:

  • Navigate to the sign-up page if required
  • Type the generated emailAddress into the username or email field
  • Enter a test password such as TestPassword123!
  • Submit the sign-up form

After submission, wait for the OTP verification screen to appear. The next step checks whether the email actually arrived.

Step 4: Wait for and extract the OTP code from the email

Now wait for the verification email and extract the one time password.

Add an HTTP Request activity configured as follows:

  • Method: GET
  • URL: https://api.mailslurp.com/waitForLatestEmail?inboxId=$inboxId&timeout=30000
  • Headers:
    • x-api-key: YOUR_API_KEY
    • Accept: application/json

Store the response in a string variable. Extract the email body and then extract the OTP code using a regular expression.

Use the following regex to find a 6 digit OTP code in the email body: \d{6}

Store the matched value in a variable called otpCode.

Step 5: Submit the OTP and assert the user is verified

Return to the Chrome browser session where the OTP form is displayed.

  • Type the extracted otpCode into the verification input field
  • Submit the verification form

Once verification succeeds, sign in again using the same email address and password. Finally, assert that the user account is verified by checking for a logged-in dashboard element, a verified account label, or another authenticated-only UI element.

This final assertion confirms that the full email OTP verification flow works end to end using UiPath and MailSlurp.

Next steps

To explore MailSlurp and UiPath: