<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Alfaz Mahmud Rizve]]></title><description><![CDATA[Alfaz Mahmud Rizve]]></description><link>https://whoisalfaz.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/6a251195330a70d7e769b4c9/51d4e8b4-bf4a-4cd9-93c5-e12c5c71d367.png</url><title>Alfaz Mahmud Rizve</title><link>https://whoisalfaz.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Tue, 01 Dec 2026 01:08:05 GMT</lastBuildDate><atom:link href="https://whoisalfaz.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to Automate Email Verification & OTP Workflows in Playwright and Pytest]]></title><description><![CDATA[Eliminate flaky test suites when testing email verification, OTP codes, and user registration flows with ephemeral disposable inboxes.]]></description><link>https://whoisalfaz.hashnode.dev/how-to-automate-email-verification-otp-workflows-in-playwright-and-pytest</link><guid isPermaLink="true">https://whoisalfaz.hashnode.dev/how-to-automate-email-verification-otp-workflows-in-playwright-and-pytest</guid><dc:creator><![CDATA[Alfaz Mahmud Rizve]]></dc:creator><pubDate>Sun, 11 Oct 2026 07:13:59 GMT</pubDate><content:encoded><![CDATA[<hr />
<h1>How to Automate Email Verification &amp; OTP Workflows in Playwright and Pytest</h1>
<p>End-to-end testing for authentication flows often fails at a single choke point: email delivery.</p>
<p>Whether verifying user signups, testing password resets, or checking multi-factor one-time passwords (OTP), relying on real email accounts (like a shared Gmail or Outlook inbox) introduces serious bottlenecks:</p>
<ol>
<li><p><strong>Rate Limits &amp; IP Blocks:</strong> Major email providers throttle incoming connections and trigger CAPTCHAs during concurrent CI runs.</p>
</li>
<li><p><strong>State Pollution:</strong> Shared mailboxes accumulate thousands of messages, making subject-line matching slow and error-prone.</p>
</li>
<li><p><strong>Flaky Race Conditions:</strong> Transactional mail delivery varies from 2 seconds to 3 minutes depending on outbound queues and greylisting.</p>
</li>
<li><p><strong>Cleanup Overhead:</strong> Purging test accounts after test execution adds maintenance burden.</p>
</li>
</ol>
<p>Using ephemeral inboxes with programmatic lifespans solves this problem. Instead of persistent inboxes, tests generate throwaway addresses that receive messages in volatile memory and automatically self-destruct.</p>
<p>Below is an end-to-end guide showing how to integrate disposable inboxes into automated test suites across Playwright (Node.js) and Pytest (Python).</p>
<hr />
<h2>Selecting the Right Inbox Lifespan for Your Test Suite</h2>
<p>Not all test runs have the same execution profile. Choosing the wrong mailbox duration can cause premature expiration or unnecessary resource waste:</p>
<table>
<thead>
<tr>
<th>Test Profile</th>
<th>Recommended Lifespan</th>
<th>Typical Use Case</th>
<th>Live Tool Reference</th>
</tr>
</thead>
<tbody><tr>
<td><strong>Fast CI Unit / API</strong></td>
<td>5 Minutes</td>
<td>Single OTP extraction, rapid smoke tests</td>
<td><a href="https://temp-mail10min.online/5-minute-mail">5-Minute Disposable Mail</a></td>
</tr>
<tr>
<td><strong>Standard Auth E2E</strong></td>
<td>10 Minutes</td>
<td>Basic signup, activation link clicking</td>
<td><a href="https://temp-mail10min.online/">10-Minute Ephemeral Mail</a></td>
</tr>
<tr>
<td><strong>Queued Webhooks</strong></td>
<td>15 Minutes</td>
<td>Third-party SMTP queues (SES/SendGrid delay)</td>
<td><a href="https://temp-mail10min.online/15-minute-mail">15-Minute Mail Buffer</a></td>
</tr>
<tr>
<td><strong>Multi-Stage Onboarding</strong></td>
<td>20 Minutes</td>
<td>Multi-tenant setup, team invites, KYC</td>
<td><a href="https://temp-mail10min.online/20-minute-mail">20-Minute Mailbox</a></td>
</tr>
<tr>
<td><strong>Staging &amp; Integration</strong></td>
<td>25 Minutes</td>
<td>End-to-end purchasing, checkout validation</td>
<td><a href="https://temp-mail10min.online/25-minute-mail">25-Minute Disposable Mail</a></td>
</tr>
<tr>
<td><strong>Manual QA &amp; Bug Triage</strong></td>
<td>30 Minutes</td>
<td>Cross-browser debugging, exploratory testing</td>
<td><a href="https://temp-mail10min.online/30-minute-mail">30-Minute Temporary Mail</a></td>
</tr>
</tbody></table>
<hr />
<h2>Implementation 1: Playwright (Node.js) with Dynamic OTP Extraction</h2>
<p>Here is a complete Playwright test suite using the zero-dependency client <code>tempmail10min-client</code> and regex extractor <code>tempmail-otp-extractor</code>.</p>
<h3>1. Install Dependencies</h3>
<pre><code class="language-bash">npm install -D @playwright/test
npm install tempmail10min-client tempmail-otp-extractor
</code></pre>
<h3>2. Playwright Test Script (<code>auth-signup.spec.js</code>)</h3>
<pre><code class="language-javascript">const { test, expect } = require('@playwright/test');
const TempMail10min = require('tempmail10min-client');
const { extractOtp, extractMagicLink } = require('tempmail-otp-extractor');

test.describe('Automated User Registration &amp; OTP Verification', () =&gt; {
  let mailClient;
  let testEmail;

  test.beforeEach(async () =&gt; {
    // 1. Initialize a 5-minute inbox for fast smoke testing
    // For slower third-party delivery pipelines, bump duration to 15:
    // https://temp-mail10min.online/15-minute-mail
    mailClient = new TempMail10min({ duration: 5 });
    const mailbox = await mailClient.createMailbox();
    testEmail = mailbox.email;
  });

  test('signs up and verifies 6-digit OTP code', async ({ page }) =&gt; {
    // Navigate to registration page
    await page.goto('https://app.example.com/register');

    // Fill registration credentials
    await page.fill('input[name="name"]', 'QA Test Runner');
    await page.fill('input[name="email"]', testEmail);
    await page.fill('input[name="password"]', 'SecureP@ssw0rd2026!');
    await page.click('button[type="submit"]');

    // Expect OTP input prompt
    await expect(page.locator('input[name="otp"]')).toBeVisible();

    // 2. Poll the ephemeral inbox for incoming verification email
    const message = await mailClient.waitForMessage({
      timeoutMs: 45000,
      pollIntervalMs: 3000
    });

    expect(message).toBeDefined();
    expect(message.subject).toContain('Verification Code');

    // 3. Extract 6-digit OTP using regex heuristic parser
    const otpCode = extractOtp(message.body_text || message.body_html);
    expect(otpCode).toMatch(/^\d{6}$/);

    // 4. Submit OTP into application
    await page.fill('input[name="otp"]', otpCode);
    await page.click('button#verify-btn');

    // Verify successful onboarding redirect
    await expect(page).toHaveURL(/.*dashboard/);
    await expect(page.locator('h1')).toContainText('Welcome to Dashboard');
  });

  test('verifies email via activation magic link', async ({ page }) =&gt; {
    // Use 15-minute lifespan for multi-stage link checks
    // Interactive tool: https://temp-mail10min.online/15-minute-mail
    await page.goto('https://app.example.com/signup');
    await page.fill('input[name="email"]', testEmail);
    await page.click('button#request-link');

    const message = await mailClient.waitForMessage({ timeoutMs: 30000 });
    const activationLink = extractMagicLink(message.body_html);

    expect(activationLink).toBeTruthy();

    // Navigate directly to the tokenized activation URL
    await page.goto(activationLink);
    await expect(page.locator('.status-badge')).toContainText('Account Confirmed');
  });
});
</code></pre>
<hr />
<h2>Implementation 2: Pytest &amp; Python Automation</h2>
<p>If your test suite uses Python, you can use the official <code>tempmail10min</code> library:</p>
<h3>1. Install Package</h3>
<pre><code class="language-bash">pip install pytest pytest-playwright tempmail10min
</code></pre>
<h3>2. Pytest Test Script (<code>test_auth_flow.py</code>)</h3>
<pre><code class="language-python">import re
import pytest
from playwright.sync_api import Page, expect
from tempmail10min import TempMail10min

def test_registration_with_temporary_email(page: Page):
    # Initialize a 10-minute temporary inbox
    # Webmail equivalent: https://temp-mail10min.online/
    client = TempMail10min(duration=10)
    mailbox = client.create_mailbox()
    temp_email = mailbox["email"]

    # Open target registration form
    page.goto("https://staging.example.com/signup")
    page.fill("#email-field", temp_email)
    page.fill("#password-field", "TestSecure123!")
    page.click("button#register")

    # Wait for incoming OTP via client polling helper
    email_data = client.wait_for_message(timeout=60, poll_interval=3)
    assert email_data is not None, "Timed out waiting for verification email"

    # Regex parse 6-digit code
    body = email_data.get("body_text", "")
    match = re.search(r"\b\d{6}\b", body)
    assert match is not None, f"No 6-digit OTP found in body: {body}"
    otp_code = match.group(0)

    # Enter OTP into verification UI
    page.fill("#otp-input", otp_code)
    page.click("button#submit-otp")

    expect(page.locator(".welcome-header")).to_contain_text("Dashboard")
</code></pre>
<hr />
<h2>Handling Delivery Delays &amp; Greylisting in CI/CD</h2>
<p>When testing against staging environments, transactional mail deliverability behaves differently than production. Two primary issues frequently appear:</p>
<h3>1. Greylisting Delays (SMTP Error 451)</h3>
<p>Mail transfer agents (MTAs) often reject initial delivery attempts from unrecognized sending IPs with a temporary 4xx error. Legitimate mail servers retry within 1 to 5 minutes.</p>
<ul>
<li><p>If your staging mail server encounters greylisting, a 5-minute inbox may expire before the retry arrives.</p>
</li>
<li><p><strong>Fix:</strong> Use an extended <a href="https://temp-mail10min.online/15-minute-mail">15-Minute Mail Buffer</a> or <a href="https://temp-mail10min.online/20-minute-mail">20-Minute Mail Session</a> in your test configuration to accommodate MTA retry intervals.</p>
</li>
<li><p>Read our deep dive on <a href="https://temp-mail10min.online/post/why-websites-block-temporary-email">Why Websites Block Temporary Email &amp; How Detection Works</a>.</p>
</li>
</ul>
<h3>2. Complex Multi-Step Onboarding</h3>
<p>Enterprise applications frequently require team confirmation: User A registers, invites User B, and User B must accept before the test completes.</p>
<ul>
<li><p>Running both signups in a single test run takes 8–12 minutes.</p>
</li>
<li><p><strong>Fix:</strong> Provision two isolated instances with a <a href="https://temp-mail10min.online/25-minute-mail">25-Minute Disposable Mailbox</a> or <a href="https://temp-mail10min.online/30-minute-mail">30-Minute Temporary Inbox</a>. This guarantees neither session drops while handling complex workflows.</p>
</li>
</ul>
<hr />
<h2>Defensive Coding: Filtering Disposable Inboxes in Production</h2>
<p>While disposable inboxes are essential for automated QA, SaaS applications often need to protect promotional credits and free trials from abuse.</p>
<p>If you are building authentication defenses, pair your verification flow with a normalization and detection engine:</p>
<pre><code class="language-javascript">const { isDisposableEmail, normalizeEmail } = require('tempmail10min-validator');

function validateRegistration(emailInput) {
  // 1. Strip subaddressing (+tag) and Gmail dot tricks
  const cleanEmail = normalizeEmail(emailInput);

  // 2. Check domain against disposable provider lists
  if (isDisposableEmail(cleanEmail)) {
    return {
      allowed: false,
      reason: 'Disposable email addresses are not permitted for trial accounts.'
    };
  }

  return { allowed: true, email: cleanEmail };
}
</code></pre>
<p>For performance benchmarks comparing delivery speeds across disposable mail providers, refer to our <a href="https://temp-mail10min.online/post/best-disposable-temporary-email-services">8 Best Disposable Temp Mail Services Tested</a>.</p>
<hr />
<h2>Summary &amp; Best Practices</h2>
<ol>
<li><p><strong>Keep durations minimal for smoke tests:</strong> Use <a href="https://temp-mail10min.online/5-minute-mail">5-Minute Mail</a> to maintain fast CI job completion.</p>
</li>
<li><p><strong>Buffer for asynchronous queues:</strong> Scale to <a href="https://temp-mail10min.online/15-minute-mail">15-Minute Mail</a> when testing SendGrid or SES queues.</p>
</li>
<li><p><strong>Use regex parsers for OTPs:</strong> Never hardcode message body indexes; parse using keyword proximity.</p>
</li>
<li><p><strong>Clean up memory automatically:</strong> Rely on volatile RAM-based deletion to keep test databases sanitized.</p>
</li>
</ol>
<p>Need an interactive disposable inbox right now? Launch a zero-signup mailbox at <a href="https://temp-mail10min.online/">TempMail10min</a>.</p>
]]></content:encoded></item></channel></rss>