Playwright vs Selenium in 2021

For a decade, Selenium was the king of E2E testing. But modern SPAs (React/Vue) flakiness made it painful. Microsoft’s Playwright (fork of Puppeteer) offers a faster, more reliable alternative by using the DevTools Protocol directly.

Auto-Waiting

Playwright waits for elements to be actionable checks prior to performing actions. No more `Thread.Sleep(5000)`!

// Playwright
await page.ClickAsync("text=Submit"); // Waits for visibility, stability, enabled...

// Selenium (Old way)
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
var btn = wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("submit")));
btn.Click();

Browser Contexts

Run isolated tests in parallel without launching new browser windows. Setup takes milliseconds.

await using var browser = await playwright.Chromium.LaunchAsync();
// Contexts are cheap and isolated (cookies, storage)
var context1 = await browser.NewContextAsync();
var context2 = await browser.NewContextAsync();

Key Takeaways

  • Playwright is **faster** and less flaky.
  • Supports **Codegen**: `playwright codegen wikipedia.org`.
  • Supports Chromium, Firefox, and WebKit (Safari) with one API.

Discover more from C4: Container, Code, Cloud & Context

Subscribe to get the latest posts sent to your email.

WordPress database error: [User 'dataadl336' has exceeded the 'max_questions' resource (current value: 40000)]
SELECT SQL_CALC_FOUND_ROWS cmxg4_comments.comment_ID FROM cmxg4_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 15486 AND comment_type NOT IN ('note') ORDER BY cmxg4_comments.comment_date_gmt ASC, cmxg4_comments.comment_ID ASC

Leave a comment

Your email address will not be published. Required fields are marked *

WordPress database error: [User 'dataadl336' has exceeded the 'max_questions' resource (current value: 40000)]
SELECT option_value FROM cmxg4_options WHERE option_name = 'akismet_comment_nonce' LIMIT 1

This site uses Akismet to reduce spam. Learn how your comment data is processed.

WordPress database error: [User 'dataadl336' has exceeded the 'max_questions' resource (current value: 40000)]
SELECT option_value FROM cmxg4_options WHERE option_name = 'cookie_consent_template' LIMIT 1

WordPress database error: [User 'dataadl336' has exceeded the 'max_questions' resource (current value: 40000)]
SELECT option_value FROM cmxg4_options WHERE option_name = 'jpsq_sync_checkout'

WordPress database error: [User 'dataadl336' has exceeded the 'max_questions' resource (current value: 40000)]
SELECT COUNT(*) FROM cmxg4_jetpack_sync_queue WHERE queue_id = 'sync'