When to Split Page Objects by Component
You'll learn: How to decide when a single page object becomes too large and should be broken down into smaller, component-specific objects.
As your page objects grow, you'll face a design question: should you keep one massive LoginPage object with 50 methods, or break it into smaller pieces like LoginForm, ErrorModal, and NavigationBar?
The Granularity Decision
A full-page object works well for simple pages. But when pages contain complex, reusable components—like modals, multi-step forms, or navigation bars that appear across multiple pages—it's time to split.
Think of it like a toolbox: you could throw all tools into one giant drawer, or organize them into smaller compartments. The second approach makes finding what you need much faster.
When to Create Component Objects
Split into smaller objects when:
- The component is reusable: A modal that appears on three different pages shouldn't have its locators duplicated three times
- The component is complex: A multi-field form with validation deserves its own object with focused methods
- The page object exceeds ~10 methods: If you're scrolling to find methods, it's too big
- Different team members own different components: Separate objects mean clearer ownership
Example Structure
Instead of CheckoutPage with 30 methods, you might have:
CheckoutPage(orchestrates the overall flow)ShippingForm(handles address input)PaymentForm(handles card details)OrderSummary(displays cart items)ConfirmationModal(handles final confirmation)
Each component object focuses on one responsibility, and CheckoutPage composes them together.
Key Takeaway: Split page objects when components are reusable, complex, or when a single object grows beyond 10-15 methods—prioritize maintainability and clear responsibilities over having fewer files.