Quick revision
The short answer
First we check whether the pilot was fair: if the Selenium tests were flaky because of sleeps, poor waits and shared data, a rewrite in any tool with better design would show most of the gain. Then we estimate the full cost, rewrite effort, retraining, CI changes, grid or vendor contracts, and lost real-Safari coverage if WebKit replaces Safari. If the case holds, we migrate incrementally: new tests in Playwright, the flakiest high-value Selenium tests rewritten first, low-value tests deleted rather than ported, page and component object structure kept so the change is mostly in the driver layer, with success measures and a checkpoint to stop.
What to remember
In this answer, we evaluated the migration by first checking whether the pilot's gains came from the tool or from better test design, using an improved Selenium version as a control. We estimated rewrite effort, retraining, CI and contract changes and the loss of real Safari coverage, and if the case held, planned an incremental migration: new tests in Playwright, flaky high-value tests first, low-value tests deleted, page and component objects kept so the change is mostly a driver layer change, with success measures and a checkpoint to stop.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
First we check whether the pilot was fair: if the Selenium tests were flaky because of sleeps, poor waits and shared data, a rewrite in any tool with better design would show most of the gain. Then we estimate the full cost, rewrite effort, retraining, CI changes, grid or vendor contracts, and lost real-Safari coverage if WebKit replaces Safari. If the case holds, we migrate incrementally: new tests in Playwright, the flakiest high-value Selenium tests rewritten first, low-value tests deleted rather than ported, page and component object structure kept so the change is mostly in the driver layer, with success measures and a checkpoint to stop.
Why this question is asked
A pilot that shows faster, more stable tests is exciting, and 1,500 tests is a big enough suite that the promise of fewer flakes is worth real money. It is also a big enough suite that a wrong decision costs a year of engineering. Interviewers ask this scenario to see whether an architecture lead can separate the effect of the tool from the effect of the rewrite, put a real price on the migration, and plan it so it can stop safely. In this answer, we will examine the pilot, estimate the costs, decide, plan the migration in increments, and define what success looks like.
1Was the Pilot a Fair Comparison?
A pilot usually takes a few dozen of the worst Selenium tests and rewrites them in Playwright. The rewritten tests are faster and less flaky. But the rewrite changed more than the tool. The pilot team probably replaced Thread.sleep calls and missing waits, used getByRole and test ids instead of positional XPath, created fresh data instead of sharing accounts, and gave each test a clean browser context. Every one of those changes would also make the Selenium tests better.
So the first step is a fair experiment. We take a sample of the same tests and rewrite them in Selenium with the same design rules: explicit waits on application states, stable locators, isolated data, a fresh session per test. Then we compare three versions over a few weeks of CI runs: the original Selenium tests, the improved Selenium tests and the Playwright tests. If improved Selenium closes most of the gap, the problem was design, and a full migration buys little. If Playwright stays clearly ahead, for example because its contexts make the suite much faster or its auto-waiting removes a class of failures the team keeps reintroducing, the tool is part of the gain.
| Version | Flake rate | Duration | What it tells us |
|---|---|---|---|
| Original Selenium | 6% | 22 min | The starting point |
| Selenium with better design | 1.5% | 14 min | Gain from design alone |
| Playwright | 1% | 9 min | Extra gain from the tool |
2Estimating the Real Cost
Rewriting is the visible cost. If a careful rewrite averages two to four hours per test including review and stabilizing, 1,500 tests is three to six thousand engineering hours, a team of several people for most of a year. On top of that come retraining testers and developers, changing the CI pipelines and reporting, and dealing with the infrastructure: an existing Selenium grid or vendor contract may not suit Playwright, or may still be under contract.
There is also a coverage cost. Playwright runs WebKit, not Safari. If our users are significantly on Safari or iOS, and today's suite runs on real Safari through a vendor, moving to Playwright loses that real-browser coverage unless we keep some Selenium or Appium tests for it. That loss must be part of the decision, not discovered afterwards.
3Planning an Incremental Migration
If the fair pilot supports the move, we do not rewrite 1,500 tests in one project. We migrate incrementally. New tests are written in Playwright from an agreed date. Existing Selenium tests are ranked by value and pain: the flakiest tests that cover high-value journeys are rewritten first, because they give the most benefit per hour. Low-value tests, ones that duplicate API coverage or check minor details, are deleted rather than ported; a migration is the cheapest moment to drop tests nobody would write today. Tests that are stable and valuable can stay in Selenium for a long time, running side by side.
Running both tools side by side for a while is normal. Both can run in the same Maven build with JUnit 5, and the reporting layer can merge results so the dashboard shows one suite.
- Does it cover a valuable journey?YesKeep evaluatingNoDelete, after checking lower-level coverage
- Is it flaky or costly to maintain?YesRewrite in Playwright earlyNoLeave in Selenium for now
- Checkpoint after each quarterflake rate, duration, maintenance hours
- Targets met?YesContinue the next batchNoStop and keep the mixed suite
4 steps in order. Play them, or step through them one at a time.
4Keeping the Structure So Only the Driver Layer Changes
The migration is much cheaper if the tests are already built on page and component objects. Tests call intentions such as checkoutPage.payWith(card), and only the page and component objects know how to find and operate elements. Then migrating means re-implementing those objects with Playwright while the test scenarios barely change. We keep the same class names and methods, and port component objects first, since they are shared by many pages.
Where the existing suite has locators and waits spread through test methods, the first step of the migration is to refactor them into page objects in Selenium. That refactoring improves the Selenium suite immediately, whatever happens next.
5Success Measures and a Checkpoint to Stop
Before starting, we write down what success means: for example, flake rate of migrated tests below one percent, suite duration for the per-commit set under fifteen minutes, and maintenance hours per month down by a third. We measure the baseline today. At each quarterly checkpoint we compare, and we agree in advance that if the numbers are not met after two checkpoints, we stop migrating and keep a mixed suite, which is a perfectly fine end state. That rule turns a large bet into a series of small ones.
6Follow-up questions
What would you do with tests nobody owns?
Tests without an owner are the first ones I would review, not port. For each, I would find the journey or feature it protects and offer it to the team that owns that feature. If no team wants it, that is a strong signal it has low value: I check whether the behaviour is covered at a lower level, add a small API or component test if it is not, and delete the UI test. Migrating an unowned test spends effort on something that will rot again, because nobody will fix it when it breaks.
Should both tools share a page object hierarchy?
Usually not the implementation, because WebDriver and Page are different types. What they should share is the interface: the same page and component object names and methods, so tests can move by changing which implementation they get. Some teams define small interfaces for component objects to make this explicit.
How do you keep people from writing new Selenium tests during the migration?
Make the new path easier: a Playwright template, examples and the component objects ready to use. A review rule or a simple build check that flags new Selenium test classes after the cutover date helps too.
7Conclusion
In this answer, we evaluated the migration by first checking whether the pilot's gains came from the tool or from better test design, using an improved Selenium version as a control. We estimated rewrite effort, retraining, CI and contract changes and the loss of real Safari coverage, and if the case held, planned an incremental migration: new tests in Playwright, flaky high-value tests first, low-value tests deleted, page and component objects kept so the change is mostly a driver layer change, with success measures and a checkpoint to stop.
Open with
My first question would be whether the pilot was fair. The pilot rewrote tests, and a rewrite usually also fixes sleeps, missing waits, positional XPath and shared test data, all of which would make Selenium tests better too.
Then, if they want more
So I would run a control: rewrite the same sample in Selenium with the same design rules and compare original Selenium, improved Selenium and Playwright over a few weeks of CI. If improved Selenium closes most of the gap, the problem is design, not the tool.
Second, I would estimate the full cost: at two to four hours per test, 1,500 tests is thousands of engineering hours, plus retraining, CI and reporting changes, grid or vendor contracts, and possibly losing real Safari coverage, because Playwright runs WebKit, not Safari. If the case still holds, I would migrate incrementally rather than in one project.
New tests go into Playwright from a set date. Existing tests are ranked: flaky, high-value journeys are rewritten first, low-value tests are deleted instead of ported, and stable valuable tests can stay in Selenium for a while, running side by side.
I would keep the page and component object structure so tests barely change and the migration is mostly reimplementing the driver layer, starting with shared component objects. Finally I would agree success measures up front, such as flake rate, per-commit duration and maintenance hours, check them every quarter, and stop with a mixed suite if they are not met.
Tests nobody owns I would offer to the feature team or delete, not port.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- JUnit 5
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- JUnit user guide, Mockito documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A team proposes migrating 1,500 Selenium tests to Playwright for Java because Playwright...": https://scrivio-interview-library.netlify.app/java/ui-testing/b307674845/