Skip to main content

Automated Email MFA/OTP Login Test

This documentation outlines the step-by-step process for performing an automated test of an email-based Multi-Factor Authentication (MFA)/OTP login using Tesmon. The procedure demonstrates Tesmon’s capabilities in dynamically handling data extraction and web interactions securely and efficiently.

Steps:

  1. Create an Email Address: Generate a unique email address at Tesmon Communications.
  2. Record the Test: Use our Chrome Extension to record the test steps.
  3. Pause for Passcode: Stop recording at the point where the passcode needs to be entered and send the session to Tesmon Desktop.
  4. Retrieve the Passcode:
    • Open a new tab in Tesmon Desktop and select COMM::EMAIL.
    • Enter the email address created in step 1 and hit send.
contact: tesmon-XXXXXX@prod.tesmonmail.xyz
within: 10000
  1. Continue Recording: Switch back to the Chrome extension, clear all steps, and resume recording. Complete the login process.
  2. Send to Desktop: Send the final steps back to Tesmon Desktop where they will be appended to the previously recorded events. You can now finalize and run the test.

Key Features

  • Dynamic Data Extraction: Tesmon seamlessly extracts the passcode from the email without any hardcoded values.
  • Enhanced Security: All sensitive data is managed dynamically, ensuring the test is both secure and robust.

Example

testbot: false
tasks:
- action: |-
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
import time

options = Options()
options.add_argument("--window-size=1512,944")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
driver = webdriver.Chrome(options=options)
actionChains = ActionChains(driver)
driver.get("https://example.com/")
- action: |-
element = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "body > div:nth-of-type(3) > div:nth-of-type(1) > div > div:nth-of-type(1) > div:nth-of-type(3) div:nth-of-type(3) a"))
).click()
- action: |-
element = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "input"))
).click()
- action: |-
element = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "input"))
).send_keys("tesmon-XXXXXX@prod.tesmonmail.xyz")
- action: |-
element = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "body > div:nth-of-type(1) > div > div:nth-of-type(2) > div > div > div:nth-of-type(1) > div:nth-of-type(2) button"))
).click()
- expect: expects.example-get-passcode
afterScript: |
import re
pattern = r"\t(\d{6})"
match = re.search(pattern, context["last_output"]["message"]["body"], re.IGNORECASE | re.DOTALL)
if match:
passcode = match.group(1)
context["passcode"] = passcode
print("Passcode found: ", passcode)
else:
assert False
- action: |-
element = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "input"))
).click()
- action: |-
element = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "input"))
).send_keys(context["passcode"])
- action: |-
element = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "body > div:nth-of-type(1) > div > div:nth-of-type(2) > div > div > button"))
).click()
- action: |-
element = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "body > div:nth-of-type(1) > div > div ul > div:nth-of-type(2) p"))
).click()