How Do I Retrieve the OTP When it’s Embedded within HTML Tags?


When an OTP is embedded within HTML tags in an email, extracting it using a regex pattern also captures the surrounding HTML symbols. To use the OTP in test execution, an addon is used to remove these extra characters and extract only the numeric value.

This article discusses how to remove the HTML tag symbols from the OTP.


Prerequisites

Before you begin, ensure that you have referred to the documentation on MailboxFunctions Function Type.


Steps to Install the Addon

  1. From the left navigation bar, go to Addons and click Add-ons. Addons
  2. Under the New & Updated Addons section, search for the Remove Special character from testdata addon and click Install. Install Addon

Steps to Remove the HTML tag symbols from the OTP

  1. In your test case, first, use the Store test data1 in test data2 NLP to store the extracted OTP in a runtime variable. NLP 1

    • Click the test data1 placeholder and replace it by selecting Data Generator from the Test Data Types dropdown. Data Generator
    • In the Data Generator overlay, configure the Get Email OTP function by selecting Default as the type, MailBoxFunctions as the function type, entering the regex pattern (for example, >\d{6}<), choosing the mailbox, setting the timeout, and clicking Save. Get email OTP
    • Enter a variable name in the test data2 placeholder. test data2
    • Click Create Step. Create Step
  2. Secondly, use the Remove Special char testdata1 from testdata2 and store it in runtime variable NLP to remove the special character from the OTP. NLP 2

    • Click the testdata1 placeholder and enter ><. testdata 1
    • Click the testdata2 placeholder and replace it by selecting Runtime from the Test Data Types dropdown. test data2
    • In the Runtime Variable overlay, select the runtime variable you created in the previous step. Runtime Variable
    • Enter a variable name in the variable placeholder. Variable
    • Click Create Step. Create Step