Page Objects Manager | Bondar Academy
Course: Playwright UI Testing with TypeScript
Module: Page Objects
Instructor: Artem Bondar
Lesson Summary
Lesson Overview: In this lesson, we will create a Page Manager , a dedicated class for managing page objects in a testing framework. This approach helps to organize tests better and reduces duplication when dealing with multiple page objects. Key Concepts: Page Object Pattern: A design pattern that encapsulates page-specific actions and elements. Page Manager: A class that manages the instantiation and access of multiple page objects, improving code organization. Steps to Create a Page Manager: Create a new file named pageManager.js in the page object folder. Import the page fixture and define a new class. Initialize fields for each page object (e.g., navigationPage , formLayoutsPage , datePickerPage ). Set up the constructor to assign the page fixture and instantiate each page object using this.page . Create methods to return instances of each page object, such as navigateTo . Refactoring Tests: In the test files, instead of importing each page object, create an instance of the Page Manager : const pm = new PageManager(pageFixture); Replace direct calls to page objects with pm.navigateTo() methods, simplifying the test structure and improving readability. Benefits: Reduced duplication of page object instances. Improved code readability and maintainability. Easy scalability for future page objects. By implementing a Page Manager , tests become cleaner and more efficient, allowing for better management of page objects as the framework grows.