July 17, 2026
Playwright vs Selenium for Testing Modern Authentication Flows With MFA, Passwordless Login, and Session Recovery
A practical comparison of Playwright vs Selenium authentication testing for MFA login testing, passwordless authentication testing, session recovery automation, and login redirect testing, with notes on when Endtest is a simpler alternative.
Modern authentication is not a single login form anymore. A realistic sign-in journey can include an external identity provider, multi-factor prompts, magic links, WebAuthn, cross-origin redirects, token refresh, forced reauthentication, and session recovery after a browser crash or network interruption. That makes Playwright vs Selenium authentication testing less about which tool can click a login button, and more about which one helps a team model the full state machine around identity, session, and recovery.
For teams evaluating browser automation for MFA login testing, passwordless authentication testing, and login redirect testing, the real question is usually this: do you want a low-level browser API with full control, or a framework that reduces how much infrastructure and state handling your team owns? Playwright and Selenium can both test modern auth flows, but they do so with different assumptions, different ergonomics, and different failure modes.
If your team wants a simpler path with less framework upkeep around login, redirects, and state recovery, Endtest is worth considering as a primary alternative. It is a managed, low-code/no-code platform with agentic AI capabilities, and it includes self-healing behavior for locator drift, which matters because auth flows often fail at the edges, not at the happy path. For teams that want less scripting overhead, self-healing tests can reduce the maintenance tax that usually grows around authentication coverage.
What makes modern authentication hard to automate
Classic username and password login is the easy case. The difficult cases share one thing in common: state changes across boundaries.
Common modern auth patterns
- MFA / 2FA, where the user must enter a code, approve a push notification, or confirm a hardware key
- Passwordless login, where a magic link, one-time code, passkey, or WebAuthn ceremony replaces the password
- External identity providers, where the app redirects to an OAuth, OIDC, or SAML flow on another origin
- Session persistence, where cookies, refresh tokens, local storage, or server-side sessions determine whether the user stays signed in
- Recovery scenarios, such as expired sessions, closed tabs, browser restarts, stale cookies, or revoked tokens
- Conditional prompts, such as step-up auth when the user visits a sensitive route or changes profile data
The automation challenge is not only locating elements. It is handling transitions between origins, timing out the right amount, persisting or resetting browser state, and making tests deterministic when the authentication provider is intentionally designed to be human-driven.
Authentication tests fail most often at the seams, not at the login field. The seams are redirects, token exchange, session expiry, and recovery after interruption.
Playwright vs Selenium at a glance
Both tools can drive browsers, but their default models differ in a way that matters for auth-heavy suites.
Playwright strengths for auth flows
Playwright was designed with modern web apps in mind. For authentication flows, its key advantages are:
- Built-in waiting behavior that reduces manual sleep calls
- First-class handling of multiple browser contexts and isolated storage state
- Practical APIs for intercepting requests, mocking network traffic, and saving auth state
- Strong cross-origin workflow support in common test patterns
- Cleaner ergonomics for tracing and debugging stateful flows
Selenium strengths for auth flows
Selenium remains valuable because it is mature, widely understood, and deeply interoperable. For authentication testing, Selenium offers:
- Broad ecosystem support across languages and infrastructure
- Strong compatibility with many existing enterprise test stacks
- A straightforward model for browser control that many teams already know
- WebDriver-based execution that fits established grid and CI patterns
The practical difference
For auth journeys, Playwright tends to reduce custom glue code around waiting, storage, and isolation. Selenium gives you more of a raw browser control surface, which is flexible but usually demands more support code, especially once you test MFA, redirects, and session recovery at scale.
That does not make Selenium obsolete. It means the maintenance burden shifts to the team. If you already have a Selenium estate and need to test authentication across legacy systems, the calculus may be “how much custom utility code can we maintain?” rather than “which tool is technically possible?”
Testing MFA login flows
MFA login testing usually includes one of four patterns: TOTP, SMS or email OTP, push approval, or hardware-backed authentication. Each has different automation implications.
TOTP and OTP-based flows
If your test environment supports a fixed seed for TOTP or a dedicated OTP mailbox, both Playwright and Selenium can handle the browser steps. The difference is usually not capability, but how much helper code you need to write around timing and retrieval.
In Playwright, the combination of automatic waits and locator APIs often makes the OTP step easier to express. In Selenium, teams often build explicit waits around the OTP field and any transition after submission.
A typical Playwright flow for entering a code might look like this:
import { test, expect } from '@playwright/test';
test('sign in with MFA code', async ({ page }) => {
await page.goto('https://app.example.com/login');
await page.getByLabel('Email').fill('qa@example.com');
await page.getByLabel('Password').fill('secret');
await page.getByRole('button', { name: 'Sign in' }).click();
await expect(page.getByText(‘Enter your verification code’)).toBeVisible(); await page.getByLabel(‘Verification code’).fill(process.env.TEST_OTP ?? ‘123456’); await page.getByRole(‘button’, { name: ‘Verify’ }).click();
await expect(page).toHaveURL(/dashboard/); });
A Selenium version usually needs a little more explicit waiting and state checking:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome() wait = WebDriverWait(driver, 10)
driver.get(‘https://app.example.com/login’) wait.until(EC.visibility_of_element_located((By.ID, ‘email’))).send_keys(‘qa@example.com’) driver.find_element(By.ID, ‘password’).send_keys(‘secret’) driver.find_element(By.CSS_SELECTOR, ‘button[type=”submit”]’).click()
wait.until(EC.visibility_of_element_located((By.ID, ‘otp’))).send_keys(‘123456’) driver.find_element(By.CSS_SELECTOR, ‘button.verify’).click() wait.until(EC.url_contains(‘/dashboard’))
The common failure modes
- OTP expires while the test is waiting on another page transition
- A provider rate limits repeated sign-in attempts
- MFA is disabled or bypassed in one environment but not another
- The UI language changes, breaking labels used by locators
- A redirect returns to a different host than the test expects
For teams that test MFA frequently, locator stability and state management matter more than raw browser command syntax. This is where frameworks often become maintenance-heavy.
Hardware keys and WebAuthn
Hardware-backed factors are harder to automate because they intentionally rely on device or OS-level trust. Both Playwright and Selenium can reach the page that requests the factor, but the actual ceremony may require a test environment, browser flags, or a mock authenticator. If your organization must validate true WebAuthn flows, expect extra environment work regardless of tool.
The decision criterion is not whether the browser can click through the dialog. It is whether your team has a reliable test harness for the identity provider and the authenticator path.
Passwordless login changes the testing model
Passwordless authentication testing is often more about orchestration than UI interaction.
Magic links and email-based login
A magic-link flow usually includes these steps:
- Request login with an email address
- Capture the email message in a test mailbox
- Extract the link or token
- Open the link in the browser
- Confirm the app establishes a session
Playwright handles the browser portion well, but the email retrieval and parsing usually live outside the framework in a custom helper or service. Selenium has the same limitation. The browser tool does not solve mail access, link extraction, or inbox polling.
That means passwordless tests often fail for reasons unrelated to browser automation, such as mailbox latency, token expiry, or environment drift. In practice, teams get more value by separating concerns: use API or mailbox utilities for message retrieval, then use browser automation only for the visible session outcome.
Passkeys and conditional UI
Passkeys and other passwordless methods can introduce modal dialogs, system prompts, or browser-managed UI. These are notoriously environment-sensitive. A test may pass locally and fail in CI because of OS differences, browser channel differences, or unavailable platform capabilities.
For this class of test, Playwright generally gives teams a better developer experience for browser-state isolation and debugging. Selenium remains viable if the organization already has a grid, device policy, and helper abstractions around the authenticator path. But if the suite becomes mostly custom infrastructure, the browser framework is only one part of the cost.
Session recovery automation is where framework choice becomes visible
Session recovery automation tests whether a system can continue after interruption. That interruption may be a browser restart, tab close, network outage, token refresh failure, or forced logout.
What to verify
A useful session recovery suite should check:
- Whether an authenticated browser context can be restored from saved state
- Whether a partially completed action survives refresh or navigation
- Whether an expired session redirects to login and then returns to the original route
- Whether state is preserved after token refresh
- Whether logout clears enough state to prevent accidental reuse
Playwright has an advantage here because it gives teams explicit browser context and storage state APIs. Saving and restoring auth state is a common pattern, especially for reusing a logged-in session across tests.
import { test } from '@playwright/test';
// Save after login
await page.context().storageState({ path: 'state.json' });
// Reuse later
const context = await browser.newContext({ storageState: 'state.json' });
const page = await context.newPage();
await page.goto('https://app.example.com/account');
Selenium can achieve similar outcomes, but the patterns are usually more manual. Teams often serialize cookies, rehydrate them into a new session, and then verify the landing page. That works, but it is easy to miss local storage, session storage, or app-specific token caches.
Login redirect testing
Login redirect testing is a frequent source of brittle failures. The test may begin on /settings, get redirected to the identity provider, then return to /settings after authentication. Failures often come from:
- Mismatched return URLs
- Encoding issues in the redirect parameter
- Stale cookies from a previous run
- Multiple tabs competing for state
- Cross-origin assumptions baked into the test script
Playwright’s context model usually makes these tests easier to isolate. Selenium can run them, but the implementation often depends on careful cleanup, explicit waits, and a clear policy for which cookies and domains are safe to preserve.
Cross-origin redirects and identity providers
Modern auth frequently crosses origins. That is normal for OIDC, OAuth, SAML, enterprise SSO, and hosted login portals.
Why cross-origin changes the testing surface
The browser enforces origin boundaries for good reasons. The test can navigate across origins, but it cannot freely inspect or control every step with the same assumptions used on a single-page app.
This creates a practical split:
- Browser automation verifies the visible journey and the final session state
- API or test harness support verifies the token or session plumbing behind the scenes
In Playwright, cross-origin navigation is generally more ergonomic because the framework was built around modern browser contexts and async flows. In Selenium, the browser can still navigate correctly, but the test author has to manage more of the synchronization and state inspection logic.
The important selection criterion is not “can it cross origins?” Both can. The criterion is “how much custom glue do we need to keep the flow readable and reliable?”
When Selenium is still the better fit
Selenium is still a sensible choice in several cases:
- Your team already has a Selenium grid, shared utilities, and existing sign-in helpers
- You need language coverage aligned with a long-lived enterprise stack
- The org has invested in WebDriver-based infrastructure and wants to extend, not replace, it
- Your auth coverage is relatively stable and not dominated by flaky state handling
In those cases, the main tradeoff is not browser capability. It is developer time. Authentication tests tend to accumulate helper methods, retries, fixture management, and environment-specific branches. That is manageable, but it is real cost.
A team should be especially cautious if it starts adding custom abstractions for every auth variant: one helper for MFA, another for magic links, another for session restore, another for redirect validation. That usually signals that the test stack is doing a lot of work that a platform might handle more cleanly.
When Playwright is the stronger framework choice
Playwright tends to be the stronger choice when the team wants:
- Faster authoring for new auth flows
- Better isolation between authenticated contexts
- Cleaner state capture and restoration
- A strong debugging story for intermittent redirect or session issues
- Fewer explicit waits and less synchronization code
For Playwright vs Selenium authentication testing, this is the biggest practical difference: Playwright reduces the amount of framework code you write to model browser state. That matters most in auth suites, because auth is stateful by design.
Still, Playwright is not a magic simplifier. You still own:
- Identity provider test accounts
- Mailbox or OTP retrieval
- Token lifetimes
- App and IdP environment coordination
- Cleanup of persistent browser data
If those responsibilities are growing faster than the team wants, a managed platform can be the more sustainable path.
Where Endtest fits as a simpler alternative
For teams that want less framework maintenance around login, redirects, and state recovery, Endtest vs Playwright and Endtest vs Selenium are useful comparisons because Endtest approaches the problem as a managed platform instead of a browser library. That matters for authentication flows, where the hidden work is often not “writing the step” but keeping the step stable over time.
Endtest’s AI Test Creation Agent and agentic workflow are relevant here because authentication flows are typically multi-step and brittle. Endtest creates standard, editable, platform-native steps inside the platform, rather than turning the result into a pile of framework code that a small subset of engineers can understand. That can make review and maintenance easier for teams that do not want auth coverage concentrated in a few developers.
Its self-healing tests are also a practical fit for login pages and redirect-heavy flows, because those pages change frequently. Label text moves, DOM structure shifts, and classes get regenerated. Endtest detects locator breakage, selects a replacement from surrounding context, and keeps the run going, which reduces the maintenance work that often accumulates in authentication suites.
The tradeoff is clear: if your team needs low-level control over every browser interaction, Playwright or Selenium gives you that control. If your main goal is to validate auth journeys without owning the framework layer, Endtest is often the simpler operational model. For organizations migrating from legacy Selenium suites, Endtest also documents migration from Selenium, which can reduce the cost of moving existing login coverage into a less code-heavy workflow.
A practical decision framework
A sensible way to choose is to score the auth suite against four questions.
1. How much state do we need to preserve?
If tests only need to sign in and assert a dashboard, any tool can work. If tests must preserve login state across tabs, browser restarts, and cross-origin redirects, Playwright’s storage-state model is usually easier than Selenium’s manual cookie handling.
2. How volatile is the UI?
If the login page changes often, a maintenance-friendly platform matters. Endtest’s self-healing behavior can reduce the amount of locator babysitting. Playwright is also resilient when written carefully, but it still expects the team to maintain selectors and helpers.
3. How much infrastructure do we want to own?
Selenium often implies more ownership of runners, grids, browser versions, and glue utilities. Playwright reduces some of that, but not all. Endtest removes much of it by moving execution and maintenance into a managed platform.
4. Who needs to work on the tests?
If only developers write and maintain auth tests, Playwright can be a strong fit. If QA engineers, SDETs, product teams, or founders need to keep coverage current without becoming framework experts, a codeless or low-code approach may be more sustainable.
A realistic recommendation by team shape
- Choose Playwright when you want modern browser APIs, strong isolation, and a cleaner path for stateful auth journeys in a code-based stack.
- Choose Selenium when you have a large existing WebDriver investment, broad language needs, or an enterprise setup that already standardizes on Selenium.
- Choose Endtest when you want to reduce maintenance around authentication flows, especially if the real pain is locator drift, redirect churn, and session recovery complexity rather than browser automation itself.
Final take
Authentication testing is a good stress test for any automation stack because it combines browser behavior, application logic, and identity infrastructure. That is why Playwright vs Selenium authentication testing is not a question of which tool can log in. Both can. The useful comparison is how much ceremony each one requires when the flow includes MFA, passwordless login, redirect chains, and recovery after interruption.
Playwright usually wins on ergonomics and state handling. Selenium still wins in legacy compatibility and ecosystem familiarity. Endtest stands apart by reducing the amount of framework maintenance your team owns, which can be the most important criterion if authentication coverage is growing faster than the test infrastructure around it.
For most teams, the best choice is the one that keeps auth tests readable, deterministic, and maintainable when the identity layer changes, not just when the first login succeeds.