Selenium WebDriver vs Playwright in a Nutshell

A quick comparison in the context of Web Test Automation

Courtney Zhan
4 min readAug 20, 2023

Update (2024–01): Check out my father’s Correcting Wrong “Playwright’s Advantage over Selenium” series. The first article was awarded “Boost” status by Medium Curators.

General

🍄 Selenium
🎭 Playwright

🍄 W3C WebDriver Standard
🎭 Not a W3C WebDriver Standard

🍄 Native support by all major browser vendors
🎭 No, downloads own browsers and does not include Chrome (has Chromium instead)

🍄 Established, first released in 2011, still active, the latest version 4.11 released three week ago (2023–07–31)
🎭 Released in 2020

🍄 Well-proven, used at Facebook and Google, was regarded the most popular web automation framework
🎭 It quickly overtook Cypress as the most popular web automation framework in the JS community.

🍄 Selenium is versatile, and works well for nearly all major programming languages. 5 official ones (Ruby, Python, Java, C# and JavaScript)
🎭 Playwright is limited to JavaScript, Python, Java and C#

🍄 Supports all major test syntax frameworks, such as RSpec, PyTest, JUnit and Mocha.
🎭 Playwright comes with its own test runner. In my opinion, it is less flexible.

Features/Limitations

Selenium is based on the W3C standard, so it is more feature complete and future proof.

Plawright does not work with Chrome (the client’s Chrome browser). Instead it installs it’s own Chromium version to use. Playwright guarantees functionality only for it’s downloaded browsers, and while executable paths can be defined to use client’s Chrome, it is generally not recommended.

Selenium can use the Ruby language, a long-time and proven good scripting language for Test Automation (since Watir, ~2003). According to the authors of the classic ‘Agile Testing Book’ (Lisa Crispin and Janet Gregory), Ruby is the best language for scripting automated tests — and I agree.

Also, “Ruby is the most in-demand skill”, according to Hired’s 2023 State of Software Engineers Report.

Playwright cannot clear text fields. It seems like a simple function to just clear a text-field. However, it does not currently exist in Playwright. Current solutions include: pressing backspace input value’s length number of times, triple clicking then deleting (source) or passing an empty string (documentation).

await page.evaluate( () => document.getElementById("inputID").value = "")

Playwright also has an auto test retry feature. If any test fails, Playwright will rerun the entire script file. I think this feature is unnecessary since it falls under the responsibility of the Continuous Testing Server rather than the automation framework.

Speed

A benchmark test running the AgileTravel login and flight tests.

Note that I ran the tests once first to warm up the test site and browser applications before I began recording the timing. Each combination was run 3 times each and approximate average is shown below.

On a Mac

Playwright with Mocha running on Chromium averaged 9 seconds.

Selenium with RSpec running on Chrome averaged 10.4 seconds.

On Windows 10

Playwright with Mocha running on Chromium averaged 9 seconds.

Selenium with RSpec running on Chrome averaged 12.2 seconds.

More about Speed

From the above tests, Playwright is quite a bit faster than Selenium Ruby. This results was different for another benchmark my father did over six months ago. It is not surprising, different test suite and different time.

“there is no value to debate the test execution speed, such as the set-up for this benchmark test, if reaching the top limit of useful range (Selenium and Playwright both did) in functional testing perspective. Still, we want to shorten the overall execution time, the only practical way is via parallel execution in a proper way”

I agree it is not much value debating the which framework is faster, given the different is minor. By running three build agents, I saved ~65% off the total execution time, plus other benefits.

Don’t Compare Apples vs Oranges

I do notice some people sing the following for Playwright over Selenium, such as:

  • Playwright has test runner
    this is provided by test syntax frameworks, such as RSpec and Mocha.
  • Playwright has built-in HTML reporters
    same as the above, this is test syntax framework, not automation framework’s responsibility.
  • Playwright API Testing
    this is done via the scripting language, using ‘httpclient’ alike libraries.
  • Playwright Auto-Waiting
    this is really a marketing thing. Selenium WebDriver’s waiting is fine, otherwise, how could Facebook’s E2E Test Automation enabled “Release twice a day”. I first heard of Auto-Wait is from TestCafe, which is no longer relevant. The next is Cypress, quite big bragging about it, the result, Cypress.io is dying.
    The best waiting mechanism is my father’ invention, check out,
    Test AJAX Properly and Efficiently with Selenium WebDriver, and Avoid ‘Automated Waiting’
  • Playwright parallel execution support
    this should be done in CT server, not automation framework.

These are not the feature of a web automation framework.

Updated (2024–01): two recent independent surveys showed a similar result. Selenium WebDriver is still the choice for web test automation, leading by a huge gap.

https://zhiminzhan.medium.com/selenium-webdriver-is-still-the-best-web-test-automation-framework-in-2024-3c0c68d38965

Playwright leads in JS automation framework at the price of Cypress, according to JavaScript Rising Stars.

https://zhiminzhan.medium.com/javascript-web-test-automation-framework-rankings-in-javascript-rising-stars-2fb6dd9ccb1e

--

--