Quick revision
The short answer
We make stable test hooks part of the UI's contract instead of something testers patch around: design system components ship with accessible roles, labels and test ids, and changing them is a reviewed change. We tie the standard to accessibility, because locating by role and name improves both; we make front-end teams own or at least run the end-to-end tests in their own pipelines, so whoever breaks a locator fixes it; we add lint rules and component checks that fail builds when interactive elements lack hooks; and we measure locator failures and repair time per team in engineering reviews.
What to remember
In this answer, we saw that locators break after refactors because elements lack stable hooks and because the people changing the markup do not see the tests fail. We made hooks part of the UI contract through the design system, linked the standard to accessibility, moved test ownership or at least test execution into the front-end teams' pipelines, enforced the standard with lint rules and component checks, and measured locator failures and repair time per team in engineering reviews.
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 make stable test hooks part of the UI's contract instead of something testers patch around: design system components ship with accessible roles, labels and test ids, and changing them is a reviewed change. We tie the standard to accessibility, because locating by role and name improves both; we make front-end teams own or at least run the end-to-end tests in their own pipelines, so whoever breaks a locator fixes it; we add lint rules and component checks that fail builds when interactive elements lack hooks; and we measure locator failures and repair time per team in engineering reviews.
Why this question is asked
When test engineers spend most of their week repairing locators after front-end refactors, the company is paying twice for every UI change: once to build it and once to make the tests notice it again. This is a classic organisational problem disguised as a technical one, and interviewers ask senior leaders about it to see whether they can move a responsibility to where the cause is. In this answer, we will look at why locators break, why it is a product engineering problem, and walk through the standard, the accessibility link, the ownership change, the automated checks and the metrics that make it stick.
1Why Locators Break When Markup Changes
A locator is the expression a test uses to find an element, such as a CSS selector or an XPath. When no stable hook exists, test engineers fall back on what they can see: the position of an element in the tree, its generated class name, or its exact text. All of those are details the front-end team is free to change. A refactor that wraps a button in a new div, swaps a CSS library or rewrites a label breaks the test even though the user experience did not change.
Notice the asymmetry. The person making the change does not see the breakage, because the UI tests run later in another team's pipeline. The person who sees it did not cause it. That is why the problem never goes away by asking testers to write better locators: they cannot write a stable locator for an element that has nothing stable on it.
2Making Stable Hooks Part of the UI Contract
The first move is to declare that testability hooks are part of a component's public interface, just like its props or its events. In practice, that means the design system's components, buttons, inputs, dialogs, grids, ship with an accessible role and label, and accept a test id that product teams set. A test id is an attribute such as data-testid="checkout-submit" that exists only so tests and tools can find the element.
Once hooks are part of the contract, changing or removing one is treated like changing an API: it shows up in review, it has a reason, and the tests that depend on it are updated in the same pull request. That single rule converts surprise breakage into planned change.
3Tying the Standard to Accessibility
The strongest argument for the standard is that it is not only about tests. Screen readers and other assistive technologies find elements by the same things good tests use: their role, such as button or checkbox, and their accessible name, the label a user hears. A form field with a proper label and a button with a real button role are easier for a blind user and easier for a test.
So we tie the testability standard to the company's accessibility goals and audits. Tools like Playwright's getByRole, and accessibility tree queries generally, let tests locate by role and name directly. When the product organisation already has accessibility commitments, sometimes legal ones, the testability work rides on that budget and priority instead of competing with it.
4Moving Ownership to the Teams That Make the Change
The organisational heart of the answer is ownership. As long as a separate test team owns the end-to-end tests, the people who break them do not feel the break. So front-end teams either own the UI tests for their area outright, or at minimum the tests run in their pull request pipelines, so a refactor that breaks a locator fails before merge, and the author fixes it while the change is fresh.
Test engineers do not disappear in this model. They move from repair work to platform work: maintaining the shared framework, component objects and test infrastructure, coaching teams, and reviewing test design. That is a better use of skilled people than chasing selectors.
- Developer refactors a componentpull request opened
- Lint and component checksinteractive elements have role, name, test id?
- Hooks missing or renamed?YesBuild fails, author fixesNoContinue
- Team's UI journeys run in the PRusing the component's hooks
- Journey broken?YesAuthor updates test in same PRNoMerge
5 steps in order. Play them, or step through them one at a time.
The person who causes a break now sees it before merge.
5Automated Checks That Enforce the Standard
A standard that depends on memory erodes in months. So we enforce it with tools. Lint rules in the front-end build, for example the accessibility rules of eslint-plugin-jsx-a11y for React or the equivalent for other frameworks, flag interactive elements without accessible names. A component test in the design system checks that every interactive component renders its role, label and test id. Automated accessibility scanners such as axe-core can run in component and end-to-end tests to catch regressions.
These checks are cheap and fast, they run on every pull request, and they make the standard visible to the people who need to follow it.
6Measuring and Reviewing It
Finally, we make the cost visible. We tag UI test failures caused by locator changes, count them per team, and measure the time from break to repair. Those numbers go into the regular engineering reviews alongside reliability and delivery metrics. A team whose refactors break tests twenty times a quarter has a concrete improvement goal; a team that hits zero gets credit.
The point of measuring is not blame. It is to show leadership that the change worked, for example that locator repair dropped from most of test engineers' time to a small fraction, and to find the teams that need help adopting the standard.
7Follow-up questions
How would you handle third-party widgets you cannot change?
We wrap them. Most third-party widgets, such as payment forms, maps or chat widgets, are embedded inside our own component, and we can put a stable test id and accessible label on our wrapper even when we cannot change the inside. A component object in the test framework then encapsulates the fragile details of the widget's internal markup in one place, so a vendor update breaks one class, not hundreds of tests. For widgets in cross-origin iframes we often test our integration with the vendor's sandbox or a stub at the API level, and keep only one or two end-to-end journeys through the real widget.
Will developers accept owning UI tests?
They accept it more readily when the tests are fast, reliable and run in their own pipeline, and when the framework makes writing a test easy. Starting with the design system and a few high-value journeys, and showing that broken builds point to real problems, builds that trust. Mandating ownership while the suite is still flaky usually fails.
Do test ids leak into production markup?
Yes, they are usually shipped. They are harmless attributes, a few bytes each. Some teams strip them from production builds, but that means production markup differs from tested markup, so many teams keep them.
8Conclusion
In this answer, we saw that locators break after refactors because elements lack stable hooks and because the people changing the markup do not see the tests fail. We made hooks part of the UI contract through the design system, linked the standard to accessibility, moved test ownership or at least test execution into the front-end teams' pipelines, enforced the standard with lint rules and component checks, and measured locator failures and repair time per team in engineering reviews.
Open with
I would treat this as an ownership problem, not a locator problem. Tests break because elements have nothing stable to find them by, and because the people changing the markup never see the failure, which lands on a separate test team later.
Then, if they want more
So first, I would make stable hooks part of the UI contract. Our design system components would ship with proper accessible roles and labels and accept a test id, and changing or removing a hook becomes a reviewed change, like changing an API, with the dependent tests updated in the same pull request. Second, I would tie this to accessibility.
Locating elements by role and accessible name is exactly what screen readers rely on, so the standard serves our accessibility commitments and audits, which gives it priority and budget.
Third, I would move ownership: front-end teams own the UI journeys for their area, or at least run them in their pull request pipelines, so whoever breaks a locator fixes it before merge. Test engineers move to platform work, the shared framework, component objects and coaching.
Fourth, I would enforce it automatically with lint rules for accessible names, design system component tests that check roles and test ids, and accessibility scanners. And fifth, I would measure locator-related failures and repair time per team and review them in engineering reviews, so we can show the improvement.
For third-party widgets we cannot change, I would put hooks on our wrapper and encapsulate the widget in one component object.
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 suites across your company break whenever front-end teams refactor markup, and...": https://scrivio-interview-library.netlify.app/java/ui-testing/c80043bdd6/