Test OTP & 2FA Email Flows
Extract one-time passwords and verification codes from emails. Test your two-factor authentication without manual copy-paste.
OTP testing is tedious and error-prone
- Manually checking email for codes slows down testing
- Codes expire quickly, causing flaky tests
- Copy-paste errors lead to false test failures
- No way to automate 2FA flows in CI/CD
Automated OTP extraction with plop
- Fetch emails via API and extract codes programmatically
- Use regex patterns to parse any OTP format
- Test expiration logic by timing your requests
- Run 2FA tests in CI/CD alongside other E2E tests
Example
Extracting OTP from Emailtypescript
import { test, expect } from '@playwright/test';
test('2FA login with OTP', async ({ page, request }) => {
const testEmail = `otp+${Date.now()}@in.plop.email`;
// Login with credentials
await page.goto('/login');
await page.fill('[name="email"]', testEmail);
await page.fill('[name="password"]', 'SecurePass123!');
await page.click('button[type="submit"]');
// Wait for 2FA prompt
await expect(page.locator('text=Enter verification code')).toBeVisible();
// Fetch OTP email
const response = await request.get(
'https://api.plop.email/v1/messages/latest',
{
params: { to: testEmail },
headers: { Authorization: `Bearer ${process.env.PLOP_API_KEY}` },
}
);
const email = await response.json();
// Extract 6-digit OTP code
const otpMatch = email.textContent.match(/\b(\d{6})\b/);
expect(otpMatch).toBeTruthy();
const otpCode = otpMatch[1];
// Enter OTP
await page.fill('[name="otp"]', otpCode);
await page.click('button:has-text("Verify")');
// Verify login success
await expect(page.locator('text=Dashboard')).toBeVisible();
});Benefits
No More Manual Testing
Extract OTP codes automatically without checking your inbox.
Fast Execution
API-based retrieval is faster than IMAP polling or manual checks.
Expiration Testing
Test that expired codes are properly rejected.
CI/CD Compatible
Run 2FA tests as part of your automated pipeline.
Related Use Cases
Related Integrations
Ready to test otp & 2fa testing?
Get started with plop.email in minutes. No credit card required.