| Feature / Criteria | 🎭 Playwright | 🌐 Selenium | 🏆 Winner |
|---|---|---|---|
| Created By | Microsoft (2020) | Thoughtworks / SeleniumHQ (2004) | Selenium — 20 yrs of history |
| Languages | JS, TypeScript, Python, Java, C# | Java, Python, C#, JS, Ruby, Kotlin | Selenium — more languages |
| Browsers | Chromium, Firefox, WebKit | Chrome, Firefox, Edge, Safari, IE | Selenium — IE support |
| Test Speed | ⚡ Very fast — parallel by default | Moderate — sequential by default | Playwright ⚡ |
| Auto-Wait | ✅ Always ON — zero setup | ❌ Manual implicit / explicit waits | Playwright ⚡ |
| Flaky Tests | Very Low — timing handled automatically | Higher — manual timing causes failures | Playwright ⚡ |
| Setup & Install | One command: npm init playwright@latest | Multiple steps: Maven + WebDriverManager | Playwright ⚡ |
| Test Runner | ✅ Built-in Playwright Test | ❌ Need TestNG / JUnit / Pytest | Playwright ⚡ |
| Parallel Tests | ✅ Automatic out of the box | ❌ Manual config via TestNG / Grid | Playwright ⚡ |
| Screenshots / Videos | ✅ Built-in, auto on failure | ❌ Need custom code to implement | Playwright ⚡ |
| HTML Reports | ✅ Beautiful reports — built-in | ❌ Need Allure or ExtentReports | Playwright ⚡ |
| Network Mocking | ✅ page.route() — intercept any API | ❌ Not built-in — need extra tools | Playwright ⚡ |
| Code Generation | ✅ npx playwright codegen — records clicks | Limited — only basic Selenium IDE | Playwright ⚡ |
| Trace / Debug Viewer | ✅ Full step + DOM snapshot replay | ❌ Not available at all | Playwright ⚡ |
| iFrame Handling | Simple: frameLocator('selector') | Manual: driver.switchTo().frame() | Playwright ⚡ |
| Multiple Windows/Tabs | context.waitForEvent('page') | getWindowHandles() loop required | Playwright ⚡ |
| API Testing Built-in | ✅ APIRequestContext included | ❌ Need RestAssured separately | Playwright ⚡ |
| Mobile Testing | Device emulation only — no real device | ✅ Appium — real Android & iOS devices | Selenium + Appium |
| Grid / Distributed | Built-in parallelism — no Grid needed | ✅ Selenium Grid — 100s of machines | Selenium (enterprise) |
| Community Size | Growing fast — 4 years old | Massive — 20 years, millions of users | Selenium — larger base |
| Job Postings (India) | Growing — ~30–40% posts mention it | Dominant — 90%+ posts require it | Selenium — more jobs NOW |
| Cloud Testing | ✅ BrowserStack / Sauce / LambdaTest | ✅ BrowserStack / Sauce / LambdaTest | Both Equal 🤝 |
| CI/CD Integration | ✅ Jenkins / GitHub Actions / GitLab | ✅ Jenkins / GitHub Actions / GitLab | Both Equal 🤝 |
| Beginner Friendliness | High — less boilerplate, auto-wait | Moderate — more config, manual waits | Playwright ⚡ |
// ✅ Install: npm init playwright@latest (one command!) // ✅ No WebDriverManager, no chromedriver downloads needed! import { test, expect } from '@playwright/test'; test('Login with valid credentials', async ({ page }) => { // Navigate — auto-waits for page load await page.goto('https://app.example.com/login'); // Fill fields — auto-waits for visibility! await page.fill('#username', 'admin@test.com'); await page.fill('#password', 'Admin@123'); // Click button — auto-waits until clickable! await page.click('button[type="submit"]'); // Assertion — built-in, no extra imports! await expect(page).toHaveURL(/dashboard/); await expect(page.getByText('Welcome Back')) .toBeVisible(); }); // Run: npx playwright test // HTML Report auto-generated → open in browser ✨ // Screenshots + Videos auto-recorded on failure 🎬
// Mock API — Selenium simply CANNOT do this! await page.route('**/api/users', route => { route.fulfill({ status: 200, body: JSON.stringify([{ id:1, name:'Test User' }]) }); }); // Test runs WITHOUT a real backend! 🚀 // Simulate errors: status: 500, 401, 404
// ⚠️ Need Maven pom.xml + Selenium + TestNG dependencies // ⚠️ Need ExtentReports/Allure for HTML reports (extra work!) import org.openqa.selenium.*; import org.openqa.selenium.chrome.*; import org.openqa.selenium.support.ui.*; import org.testng.Assert; import org.testng.annotations.*; public class LoginTest { WebDriver driver; WebDriverWait wait; @BeforeMethod public void setup() { driver = new ChromeDriver(new ChromeOptions()); driver.manage().window().maximize(); wait = new WebDriverWait(driver, Duration.ofSeconds(15)); } @Test public void loginTest() { driver.get("https://app.example.com/login"); // Find elements manually every time driver.findElement(By.id("username")) .sendKeys("admin@test.com"); driver.findElement(By.id("password")) .sendKeys("Admin@123"); // Must explicitly wait — or it may fail! wait.until(ExpectedConditions .elementToBeClickable( By.cssSelector("button[type='submit']"))) .click(); wait.until(ExpectedConditions .urlContains("dashboard")); Assert.assertTrue( driver.getCurrentUrl().contains("dashboard")); } @AfterMethod public void teardown() { driver.quit(); } } // HTML Report → set up Allure/Extent separately
// playwright.config.ts — all browsers at once! projects: [ { name:'Chrome', use:{...devices['Desktop Chrome']} }, { name:'Firefox', use:{...devices['Desktop Firefox']} }, { name:'Safari', use:{...devices['Desktop Safari']} }, { name:'iPhone14',use:{...devices['iPhone 14']} }, { name:'Pixel7', use:{...devices['Pixel 7']} }, ] // ONE command runs all: npx playwright test ✅
# Opens browser — click around to record! npx playwright codegen https://example.com # Test code is written automatically as you click # Save → Run → Done! Perfect for beginners 🎯 # Works with any website. Generates locators too!
// Playwright smart locator methods page.getByRole('button', { name: 'Login' }) page.getByLabel('Email address') page.getByPlaceholder('Enter your email') page.getByTestId('submit-btn') page.getByText('Welcome Back') // More resilient than fragile XPath! 💪
// Connect tests to Selenium Grid Hub ChromeOptions options = new ChromeOptions(); WebDriver driver = new RemoteWebDriver( new URL("http://hub-host:4444/wd/hub"), options ); // Runs across hundreds of machines! 🏭 // Different OS + browser combinations at once!
// Same WebDriver protocol → works with Appium! DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("platformName", "Android"); caps.setCapability("deviceName", "Pixel 7"); caps.setCapability("app", "/path/to/app.apk"); caps.setCapability("automationName", "UiAutomator2"); // Real device — Android & iOS 📱 // Learn Selenium → easy move to Appium!
// POM pattern — every company uses this! public class LoginPage { @FindBy(id="username") WebElement usernameField; @FindBy(id="password") WebElement passwordField; @FindBy(id="loginBtn") WebElement loginButton; public void login(String u, String p) { usernameField.sendKeys(u); passwordField.sendKeys(p); loginButton.click(); // Reusable ♻️ } }