How to automate email based Two Factor Authentication(2FA)


Prerequisites

  • A Testsigma account. If you do not have one already, sign up for a free trial
  • Understanding of creating and running test cases.
  • Provisioned mailbox.
  • Familiarity with regular expressions. If not, refer to Regex guide - MDN Docs.

  • Steps for email-based 2FA automation

    Step 1: Record elements

    Before moving on to the test case, you must capture elements on the login screen of your application. For more information on how to record elements using Testsigma chrome recorder extension, refer to

  • Web application
  • Android
  • iOS

  • Step 2: Configure the mailbox

    Testsigma provides you with a valid mailbox on request, with which you can author any test case that requires a valid mailbox connected to an email id.

    NOTE:

    The 2FA testing (email and phone number) is offered as part of the enterprise plan. The feature is available for the below mentioned countries & supported for SMS OTP.
    Australia, Canada, USA, Czech Republic, Denmark, Hungary, Indonesia, Mexico, Netherlands, Romania, Slovakia, Sweden, United Kingdom. For other regions, contact sales.

    Step 3: Create a test case

    If you are not familiar on how to create a simple test case, refer to create a testcase

    Step 4: Create a test steps to enter the email address where the OTP is to be sent

    We will enter the email address provided by Testsigma using the Mailbox test data type in the test step.

    1. In your test case, add a test step to enter the email in the email field on your application page.
    2. Clear the test data placeholder and select the &|Mailbox| test data type from the suggestions list. An overlay showing the list of available Email addresses will open up.
    3. Next, use the NLP Click on SendOTPto generate the OTP.

    Step 5: Create a test step to fetch the OTP from the mailbox

    We will use the test data generators available in Testsigma to fetch the OTP from the Mailbox selected in the previous step.

    1. Add a test step to enter the OTP Code in the OTP Field. For this, select the NLP Enter test data in the EmailOTP field
    2. Clear the test data placeholder and select the !|Function| test data type
    3. Search and select the Test Data generator function !|MailboxFunctions - getOTP|
    4. Enter the below arguments for the function and create the test step.
      1. Regex: The Regex command specifies the format of the OTP i.e alphanumeric or pure number or pure alphabetical etc. For example: for an OTP which is a number with a length of 4 to 8, we can use the regular expression \d{4,8}.
      2. Mailbox: The Mailbox is the pre-configured email ID to which the OTP is sent. In this case it is automation@testsigatech.com
      3. Timeout: How long should be the wait time for the OTP to be generated
    5. Once these values are passed the MailBox reader will use the parameters to read the generated OTP.
    The below GIF depicts the method to automate email based OTP verification in real time using a sample application: email 2fa automation