QA Interview Hub · Knowledge base · Quizzes · Українська

Selenium + Java › WebDriver: architecture and drivers

Selenium or Playwright: the difference and how to choose

Selenium drives browsers through drivers following the W3C standard, while Playwright drives Chromium, Firefox and WebKit through one API. Selenium leaves the runner and reports to the team, while Playwright for JS/TS has its own runner, Playwright Test, with isolation and parallelism. A large existing suite, real Safari or a working Grid favours Selenium, while Playwright is a common pick for a new project.

Selenium · Comparison

A team has 800 Selenium tests and someone asks: "Should we move to Playwright?" What do you answer?

"Selenium or Playwright" sounds like a choice between old and new, but the real difference is what each tool considers its job. This lesson gives the criteria used to decide it on a project and to answer in an interview.

How it works and why. Selenium WebDriver drives a real browser through a driver supplied by the browser vendor, following the W3C WebDriver standard. That is why its API is the same for Chrome, Edge, Firefox and Safari, and Java, Python, C#, Ruby and JavaScript have their own bindings (Kotlin uses the Java one). Playwright drives Chromium, Firefox and WebKit through one API; for these it uses its own browser builds, and it runs branded Chrome and Edge when they are installed. It does not work with branded Firefox or Safari: its WebKit is an engine build, not Safari. Playwright is available for Node.js, Python, .NET and Java.

The second difference is how much work the tool takes on. Selenium is an API for driving a browser: its documentation says outright that it does not help you write well-architected test suites, so the team assembles the runner, reports and project structure. Playwright for Node.js has its own runner, Playwright Test: isolation (every test in its own BrowserContext), workers, sharding and an HTML report. In Java, Python and .NET Playwright works with JUnit or TestNG, pytest, NUnit or MSTest, so parallelism and reports come from that framework, while the trace viewer is available in every language.

SeleniumPlaywright
BrowsersBranded: Chrome, Edge, Firefox, SafariChromium, Firefox, WebKit; installed Chrome and Edge
LanguagesJava, Python, C#, Ruby, JS, KotlinJS/TS, Python, .NET, Java
WaitingSet up in the test: implicit or explicit waitsAuto-wait for actions, retrying assertions
Runner and reportsYour choice: JUnit, TestNG and so onPlaywright Test (JS/TS); in Java, Python, .NET: JUnit/TestNG, pytest, NUnit
ParallelismJUnit 5 or TestNG, Grid across machinesWorkers and sharding in Playwright Test; in other languages via the framework
IsolationA new driver sessionA new BrowserContext per test (in Java created in @BeforeEach)
Browser eventsWebDriver BiDiBuilt into the API

Example: the same action. In Selenium you write the wait explicitly, otherwise the test reaches for an element that is not there yet. The documentation says Selenium does not wait for dynamically added elements by default, and the implicit wait defaults to 0.

// Selenium
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.elementToBeClickable(By.id("pay"))).click();
// Playwright
await page.getByRole('button', { name: 'Pay' }).click(); // waits until the button can be clicked

Before an action Playwright checks that the element is visible, stable, receives events and is enabled, and waits until that holds, failing with a TimeoutError on timeout. This shrinks the waiting code but does not remove the need to understand what the test is waiting for.

When to choose which.

  • Selenium: a huge existing suite, a Java team with RestAssured and Page Object, a need to test real Safari or other browsers through their own drivers, an existing Grid with different browser versions and operating systems;
  • Playwright: a new project, several contexts and tabs in one test, Playwright Test parallelism and the trace viewer out of the box, network mocking in the core API (in Selenium network interception comes through WebDriver BiDi), a TypeScript team;
  • Either: a typical UI regression. Then the team's language, the existing code and the maintenance time decide.

Limits and common mistakes. Neither tool gives a stable test for free: flakiness most often comes from data, environment and locators.

  • Migrating "to be modern": rewriting hundreds of tests has a cost, and the gain depends on the pain you really have (flaky tests, run time, missing debugging tools);
  • Comparing "speed" without a reason: run time depends on parallelism, data and environment, not only on the tool;
  • Treating Playwright's WebKit as a replacement for checking in real Safari;
  • Mixing implicit and explicit waits in Selenium: the documentation warns it gives unpredictable wait times.

Check yourself

A team has a Java suite on Selenium with Grid and only wants fewer flaky tests. Is Playwright automatically needed?

Answer

No. First find the cause of the flakiness: data, waits, locators, environment. Fixing waits and data isolation is often enough. A migration is justified when what hurts is exactly what the other tool gives out of the box, and there is capacity to rewrite the suite.

Why does Selenium need explicit waits while Playwright usually does not?

Answer

Selenium does not wait for dynamically added elements by default and its implicit wait is 0. Playwright runs actionability checks before every action and retries assertions, so waiting code is written only for your own logic.

In an interview. Junior: Selenium drives branded browsers through their drivers following the W3C standard and works with many languages. Playwright drives Chromium, Firefox and WebKit through one API, waits for elements by itself and, for JS/TS, has a built-in runner, Playwright Test, with isolation and parallelism. Middle/Senior: I do not migrate for fashion. I look at the team's language, the browsers needed (including real Safari), the existing Grid infrastructure, the size of the suite and what actually hurts. For a new TypeScript project I take Playwright, and for a large Java suite with a working Grid I first fix the causes of flakiness and estimate the cost of migration.

More articles in this chapter