Agent Detection Checklist
Relevant source files
The following files were used as context for generating this wiki page:
The Agent Detection Checklist is a framework within the playwright-page-object library designed to help developers and AI agents identify the existing architectural patterns in a codebase. Because the library supports multiple implementation styles—ranging from raw Playwright locators to fully encapsulated Page Object Models (POM)—detecting the current state is critical for maintaining consistency during incremental adoption or refactoring.
This checklist ensures that new tests or page objects align with the project's established "Root Style," "Child Output Style," and "Instantiation Style."
Sources: skills/playwright-page-object/SKILL.md:20-25, README.md:16-25
1. Detection of Root Style
The first step in analyzing a playwright-page-object implementation is determining how top-level classes are structured. The library allows for two primary root styles: plain decorated classes and built-in root objects.
- Plain Decorated Class: A standard class where the first constructor argument is a Playwright
Page. It uses@RootSelector(...)but does not inherit from library base classes. - Built-in Root (
RootPageObject): A class that extendsRootPageObject. This is typically used when the project requires out-of-the-box helpers like assertions and waits at the root level.
Root Style Comparison
| Feature | Plain Decorated Class | RootPageObject |
|---|---|---|
| Inheritance | None (Plain Class) | Extends RootPageObject |
| Constructor | (page: Page, ...rest) | Handled by base class |
| Usage Context | Incremental adoption | Full POM framework |
Sources: skills/playwright-page-object/SKILL.md:27-31, README.md:120-125
The diagram above illustrates the logic used to identify the root architecture of a page object class.
Sources: skills/playwright-page-object/SKILL.md:46-52, README.md:47-55
2. Detection of Child Output Style
The library is flexible regarding what a decorated accessor returns. Identifying this style is crucial for determining how to interact with elements in tests.
- Locator-first: Accessors return a raw Playwright
Locator. Interaction is done via standard Playwright methods (e.g.,this.PromoCodeInput.fill()). - External Controls: Accessors return a custom class (not extending
PageObject) that typically accepts aLocatorin its constructor. - Built-in
PageObject: Accessors return aPageObjectinstance, providing the$property and built-in wait/assertion methods. ListPageObject: Used for collections of repeated elements, providing async iteration and filtering.
Sources: skills/playwright-page-object/SKILL.md:32-37, README.md:73-85
Implementation Patterns
// Locator-first (README.md:94)
@Selector("PromoCodeInput")
accessor PromoCodeInput!: Locator;
// External Control (README.md:112)
@Selector("PromoCodeInput", ExternalInputControl)
accessor PromoCode!: ExternalInputControl;
// Built-in POM (README.md:138)
@Selector("PromoCodeInput")
accessor PromoCode = new PageObject();
3. Instantiation and Fixture Detection
The checklist requires identifying how page objects are brought into tests. This affects how the "Agent" should write new test files.
createFixtures(...): Look forbase.extend(createFixtures({ ... }))in fixture files. This is the preferred method for automatic dependency injection.- Manual Instantiation: Look for
new MyPage(page)insidetestblocks orbeforeEachhooks.
Sources: skills/playwright-page-object/SKILL.md:38-40, example/README.md:46-55
The sequence diagram demonstrates the two ways instances are provided to the test environment.
Sources: README.md:173-188, src/tests/fixtures.spec.ts:38-45
4. Custom Component Rules
If the detection reveals custom PageObject subclasses, the following rules must be verified:
- Constructor Shape: If a subclass of
PageObjectuses a custom constructor that deviates from(page, root, selector), it must implementcloneWithContext(). - Nesting constraints:
@RootSelectormust never be used on a class extendingPageObjectdirectly; it is reserved for the root class orRootPageObject. - Lazy Resolution: All decorated properties must use the
accessorkeyword to ensure selectors remain lazy and are rebuilt only when accessed.
Sources: skills/playwright-page-object/SKILL.md:41-43, src/page-objects/PageObject.ts:88-92, src/tests/page-objects/PageObject.advanced.spec.ts:87-95
Summary of Decision Rules
| Situation | Recommended Action | Source |
|---|---|---|
| User has existing standard classes | Use Plain Decorated Root | SKILL.md:70 |
| Codebase uses helpers consistently | Use RootPageObject | SKILL.md:85 |
| Repeated UI patterns found | Use External Controls | SKILL.md:106 |
| Element requires built-in waits | Use PageObject | SKILL.md:94 |
| Repeated list items found | Use ListPageObject | SKILL.md:101 |
The Agent Detection Checklist ensures that regardless of the entry point, the implementation maintains the structural integrity and chosen abstraction level of the project.
Sources: skills/playwright-page-object/SKILL.md:68-115, README.md:190-205