Quick revision
The short answer
We model each design system component, DatePicker, DataGrid, Modal, as a component object scoped to a root element, and build page objects by composing them, so the details of how a date picker works live in one class instead of on 60 pages. Components are found by stable test ids or roles that the design system provides, and component objects are versioned with the design system. Shared behaviour such as waiting for loading or dismissing toasts goes into a base layer, a small suite runs the component objects against the design system's showcase page, and test data builders stay separate from UI objects.
What to remember
In this answer, we saw that page-only objects copy component knowledge onto every page, so one design system change breaks hundreds of tests. We built component objects scoped to a root locator, composed them into thin page objects, put cross-cutting waits and toast handling in a base layer, tested the component objects once against the design system's showcase and versioned them with it, and kept test data builders separate from UI objects.
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 model each design system component, DatePicker, DataGrid, Modal, as a component object scoped to a root element, and build page objects by composing them, so the details of how a date picker works live in one class instead of on 60 pages. Components are found by stable test ids or roles that the design system provides, and component objects are versioned with the design system. Shared behaviour such as waiting for loading or dismissing toasts goes into a base layer, a small suite runs the component objects against the design system's showcase page, and test data builders stay separate from UI objects.
Why this question is asked
A design system is a gift to a UI test suite, but only if the tests are shaped like it. When page objects reach into the internals of a shared date picker on 60 different pages, one upgrade of that date picker breaks hundreds of tests overnight. Interviewers ask this design question to see whether we can apply the same reuse the front-end team already has to the test code. In this answer, we will see why page-only objects break so widely, build component objects scoped to a root, compose them into pages, add a base layer for shared behaviour, test the component objects once against the showcase, and keep data setup apart.
1Why Page-Only Objects Multiply One Change
A design system is a library of reusable UI components, built once and used across the product. A date picker on the booking page and on the invoice page is the same component with the same internal markup.
If every page object writes its own code to operate the date picker, finding the calendar button, clicking the month arrow, picking the day cell, then that knowledge is copied 60 times. When the design system team changes how the calendar renders, every copy breaks, and every test that touches a date fails. The test suite has lost the reuse that the product code has.
2Building Component Objects Scoped to a Root
A component object is like a page object for one component. Its key feature is scope: it is created with the root element of one instance of the component, and all its locators search inside that root. So two date pickers on the same page do not confuse each other, and a locator like a day cell cannot accidentally match something elsewhere on the page.
Notice that the internal test ids, such as ds-datepicker-toggle, belong to the design system, not to any product page. They are provided by the component itself, so every instance has them. If the date picker changes its internals, only this class changes, and it changes once.
3Composing Pages From Components
Page objects now become thin. They know which components the page has and where each one is, identified by a test id the product team sets on that instance, and they expose intentions built on top of the components.
- Testsscenarios and assertions
- Page objects
BookingPage,InvoicePage: compose components, expose intentions - Component objects
DatePicker,DataGrid, Modal: one class per design system component - Base layerwaits for loading, toast dismissal, screenshots
- WebDriverthe browser
5 layers, from the top down. Step through them one at a time.
Each kind of change lands in exactly one layer.
So a design system change to the DataGrid touches one class, DataGrid, and the 60 pages and hundreds of tests that use it keep working. A product change to the booking page touches BookingPage only.
4A Base Layer for Cross-Cutting Behaviour
Some behaviour is needed everywhere: waiting for the application's loading indicator, dismissing notification toasts that cover buttons, scrolling an element into view, capturing a screenshot. If each page object writes its own version, they drift apart and some are wrong. So we put them in a base class or a helper that every page and component uses, such as a BaseComponent with waitUntilIdle() and dismissToasts().
The design system often helps here too: if its components set a common attribute while busy, for example aria-busy="true", one wait in the base layer works for every component.
5Testing Component Objects Once, Against the Showcase
Most design systems have a showcase or documentation site, often built with a tool such as Storybook, that renders every component in isolation. That is the perfect place to test our component objects. A small suite opens each component's showcase page and exercises its component object: select a date, sort the grid, open and close the modal.
When the design system releases a new version, this suite runs first. If DatePicker breaks, we see one clear failure in the component suite, fix one class, and release a new version of the component objects alongside the design system version. The product suites never see the break. That is what versioning component objects with the design system means in practice: component objects 5.2 match design system 5.2.
6Keeping Data Setup Apart From UI Objects
Finally, test data builders and API setup helpers live in their own classes, not in page or component objects. A test that needs a booked room creates it through the booking API with a builder, then opens the page. Mixing data creation into UI objects ties them to one scenario and makes them slow, because setup would go through the UI. Separate layers keep each piece reusable.
7Follow-up questions
Who should own the component objects?
Ideally the design system team, or a test platform team working closely with it. They are the people who know when a component's internals change, and they can update the component object in the same release. If the design system team owns them, a change to a component ships with an updated component object and its showcase tests, which is the strongest guarantee that product suites will not break. Product teams own their page objects and tests, and contribute to component objects through pull requests when they need a new capability.
What if a page uses a component in an unusual way?
The page object can add a page-specific method on top of the component object, but it should not reach into the component's internals. If many pages need the same unusual action, that action belongs in the component object itself.
How do we find a component instance when the product team did not add a test id?
We can scope by an accessible label or by a nearby heading, but that is weaker. The better fix is to make the test id a required or standard property of design system components, so every instance can be given one.
8Conclusion
In this answer, we saw that page-only objects copy component knowledge onto every page, so one design system change breaks hundreds of tests. We built component objects scoped to a root locator, composed them into thin page objects, put cross-cutting waits and toast handling in a base layer, tested the component objects once against the design system's showcase and versioned them with it, and kept test data builders separate from UI objects.
Open with
I would mirror the design system in the test code. For each component, DatePicker, DataGrid, Modal and so on, I write a component object that is created with a root locator for one instance and searches only inside that root, so two date pickers on a page do not interfere and the internal details live in one class.
Then, if they want more
The design system provides stable internal test ids and roles that the component objects rely on, and product teams set a test id on each instance. Page objects become thin: BookingPage holds two DatePickers and a DataGrid, located by those instance ids, and exposes intentions like chooseDates.
Then a change to the date picker's markup touches one class instead of 60 pages. Cross-cutting behaviour, waiting for the loading indicator, dismissing toasts, scrolling, screenshots, goes into a base layer every component uses.
I would also write a small suite that runs each component object against the design system's showcase page, such as Storybook, so when a new design system version is released, any break shows up once, there, and we release matching component objects versioned with the design system.
Test data builders and API setup helpers stay separate from UI objects, so tests create data quickly through APIs and the UI objects stay reusable. On ownership, I would want the design system team, or a platform team next to it, to own the component objects, so changes ship together.
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 "Your web application has a design system with reusable components (date picker, data...": https://scrivio-interview-library.netlify.app/java/ui-testing/b3c0e56fd9/