Quick revision
The short answer
We cut the suite before buying or building anything: remove duplicate coverage, move checks down to API and component tests, and run only the critical journeys on every commit with the full browser matrix nightly. Then we compare the real costs of the vendor against self-hosting Grid on Kubernetes, nodes, autoscaling with KEDA on the session queue, video and log storage and the people to run it, and the coverage each gives. A mix is common: a self-hosted Grid for the bulk on Chromium and Firefox, and the vendor for real Safari and mobile devices, chosen by measuring queue time, session start time, flake rate by infrastructure and cost per run.
What to remember
In this answer, we cut the run time first by moving checks to API and component tests, removing duplicates, and running critical journeys per commit with the full matrix nightly. We compared self-hosting Grid on Kubernetes, with KEDA autoscaling on the session queue, storage and operating people, against a vendor's coverage of real Safari and devices, chose a common mix of self-hosted Chromium and Firefox with the vendor for Safari and devices, and measured queue time, session start time, flake rate by infrastructure and cost per run.
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.
We cut the suite before buying or building anything: remove duplicate coverage, move checks down to API and component tests, and run only the critical journeys on every commit with the full browser matrix nightly. Then we compare the real costs of the vendor against self-hosting Grid on Kubernetes, nodes, autoscaling with KEDA on the session queue, video and log storage and the people to run it, and the coverage each gives. A mix is common: a self-hosted Grid for the bulk on Chromium and Firefox, and the vendor for real Safari and mobile devices, chosen by measuring queue time, session start time, flake rate by infrastructure and cost per run.
Why this question is asked
A three-hour UI run and a large vendor bill are two symptoms of one problem, and a proposal to self-host Grid treats only the second. Interviewers ask this scenario to see whether a senior engineer can avoid the tempting infrastructure project, cut the work first, and then make a build-versus-buy decision on total cost and coverage rather than on the invoice alone. In this answer, we will shrink the suite, compare the two options honestly, look at a mixed model, and decide what to measure so the decision can be checked.
1First Question: Why Does the Suite Take Three Hours?
Before choosing where browsers run, we should ask how many browser minutes we really need. Run time is roughly the number of tests times the average test duration, divided by how many run at once. Both a vendor and a self-hosted Grid charge for browser time in some form, so every test we remove saves money on either side.
In large suites, a lot of UI tests check things a cheaper test could check: form validation rules, calculations, error messages from the API. Others duplicate each other, because several teams wrote similar journeys. So the first step is to classify the suite and cut.
2Cutting the Suite Before Scaling It
We go through the tests by journey. Checks of business rules move to API tests, which run in milliseconds. Checks of component behaviour move to component tests that render one component without a browser grid. Duplicate journeys are merged. What remains in the UI layer are the critical user journeys: sign up, log in, search, checkout, payment and the few flows that only make sense end to end.
Then we split when tests run. On every commit, only the critical journeys run on one browser, a set that finishes in about ten to fifteen minutes. The full matrix, all browsers and the long tail of UI tests, runs nightly. In a typical cleanup, this alone takes the per-commit run from three hours to well under twenty minutes and cuts browser minutes by more than half, before we have changed any infrastructure. The exact numbers depend on the suite; the point is to measure them.
- Classify each UI testjourney, business rule, component behaviour, duplicate
- Rule checked better by API test?YesMove it to the API suiteNoKeep evaluating
- Duplicate of another journey?YesMerge or deleteNoKeep
- Critical journey?YesPer-commit smoke setNoNightly full matrix
- Then size infrastructureon the browser minutes that remain
5 steps in order. Play them, or step through them one at a time.
The cheapest browser minute is the one we no longer need.
3What Self-Hosting on Kubernetes Really Costs
Self-hosting Grid on Kubernetes means running the Grid router and browser node pods in our cluster. The docker-selenium project publishes images and a Helm chart, and it can autoscale browser nodes with KEDA, an autoscaler that reads the Grid's new session queue and adds nodes when sessions wait, removing them when the queue is empty.
The visible cost is the Kubernetes nodes: a Chrome session needs roughly one CPU core and one to two gigabytes of memory to run reliably, so 50 parallel sessions need a meaningful pool of machines, at least while runs are active. The less visible costs are storage for video and logs, network egress, the work to keep images and browser versions updated, and above all the people: someone must be on call when the Grid breaks at 2 a.m. before a release. A fair comparison counts a share of one or two engineers' time.
Self-hosting also covers only some browsers cheaply. Chrome, Firefox and Edge run in Linux containers. Real Safari only runs on macOS, so self-hosting Safari means running Mac hardware, which is a different and more expensive kind of fleet, and real mobile devices are harder still.
4What the Vendor Gives Us
A cloud browser vendor charges per parallel session or per minute, and in return provides many browser and operating system versions, real Safari on macOS, real iOS and Android devices, video, logs and dashboards, and no infrastructure to run. For a company with customers on many devices, that coverage is hard and expensive to build.
So the honest comparison is not the invoice against cluster costs. It is the vendor's cost for the coverage we need against the full cost of self-hosting the same coverage, including people and the browsers we could not run ourselves.
| Factor | Self-hosted Grid | Cloud vendor |
|---|---|---|
| Chrome, Firefox, Edge | Cheap at scale in containers | Included, priced per session or minute |
| Real Safari | Needs macOS hosts | Included |
| Real mobile devices | Very hard to run | Included, often extra cost |
| Scaling | KEDA on the session queue | Vendor's concurrency limit |
| Video and logs | Our storage and retention | Included in dashboards |
| Operations | Our team, on call | Vendor support |
| Data locality | Inside our network | Needs tunnel to test environments |
5The Common Answer: A Mix
Many companies end up with a mix. The self-hosted Grid takes the bulk of the volume, the per-commit runs and nightly runs on Chromium and Firefox, where containers are cheap and runs stay inside our network close to the test environments. The vendor takes the parts that are expensive to own: real Safari, real mobile devices and older browser versions, usually in the nightly or pre-release run, with far fewer sessions than before.
For this to work, tests must be portable: the driver factory reads the Grid URL and capabilities from configuration, so the same test can run on either provider. That also keeps us free to renegotiate or switch later.
6Measuring End to End
To decide and to check the decision, we measure the whole path, not just the test duration. Queue time is how long a session request waits for a slot. Session start time is how long it takes from request to a ready browser. Flake rate by infrastructure shows whether one provider produces more environment failures. Cost per run divides the monthly cost, including people, by the number of runs. With these four numbers for both options during a pilot of a few weeks, the decision is a comparison of facts rather than opinions.
7Follow-up questions
How would you autoscale Grid nodes on Kubernetes?
With KEDA, which has a scaler for Selenium Grid. KEDA polls the Grid's GraphQL endpoint for the number of queued session requests and running sessions per browser, and scales the matching node deployment, or creates node jobs, so that each waiting request gets a pod. Using one session per node pod with jobs that exit after the session gives clean browsers and makes scale-down safe. The Kubernetes cluster autoscaler then adds or removes machines as pods need them. We set a maximum to cap cost, and keep a small minimum of warm nodes so the first tests of a run do not wait for machine start-up. The docker-selenium Helm chart can set most of this up; check its documentation for the version we deploy.
What if the test environments are inside a private network?
A self-hosted Grid in the same network reaches them directly. A vendor needs a secure tunnel, which most vendors provide as a small agent we run inside our network. The tunnel adds latency and is another component that can fail, so it belongs in the comparison.
Is a faster run worth more than a cheaper run?
Usually yes, within reason. Developer time waiting for feedback is expensive, so we optimize the per-commit run for speed and the nightly run for cost.
8Conclusion
In this answer, we cut the run time first by moving checks to API and component tests, removing duplicates, and running critical journeys per commit with the full matrix nightly. We compared self-hosting Grid on Kubernetes, with KEDA autoscaling on the session queue, storage and operating people, against a vendor's coverage of real Safari and devices, chose a common mix of self-hosted Chromium and Firefox with the vendor for Safari and devices, and measured queue time, session start time, flake rate by infrastructure and cost per run.
Open with
I would not start with the infrastructure question, because a three-hour suite is expensive on any infrastructure. First I would cut the work: classify the UI tests, move business-rule checks to API tests and component behaviour to component tests, merge duplicate journeys, and keep in the UI layer only critical journeys.
Then, if they want more
Then I would split by schedule: a fast set of critical journeys on one browser on every commit, aiming for under fifteen minutes, and the full matrix nightly. That usually removes more than half the browser minutes before we touch infrastructure. Then I would compare the two options on total cost and coverage.
Self-hosting Grid on Kubernetes means node pods, autoscaling with KEDA on the Grid's session queue, storage for videos and logs, keeping images updated, and the engineers who run and support it, which is the cost people forget.
It covers Chrome, Firefox and Edge cheaply in containers, but real Safari needs macOS hosts and real mobile devices are very hard to own. A vendor covers those and needs no operations. So I would expect a mix: self-hosted Grid for the bulk of Chromium and Firefox runs, the vendor for Safari and devices, with tests portable through configuration.
To decide, I would pilot both for a few weeks and measure queue time, session start time, flake rate by infrastructure and cost per run including people, and choose on those numbers.
About this answer
- Last updated
- 12 November 2026
- 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 "UI test runs take 3 hours and the company pays a cloud browser vendor heavily, while...": https://scrivio-interview-library.netlify.app/java/ui-testing/75fe9c6d5b/