You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+95-53Lines changed: 95 additions & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,16 +8,21 @@ Every piece of UI becomes a class. Every selector becomes a typed accessor. Ever
8
8
9
9
-**Everything is a PageObject**: No artificial hierarchy between "pages" and "components". A modal, a button, and a page are all constructed the exact same way.
10
10
-**Strongly Typed over Stringly-Typed**: Eliminate raw locator strings in tests completely. Tests only use typed accessors.
11
-
-**Composable over flat**: Controls nest inside controls to mirror the actual DOM structure.
11
+
-**Composable over flat**: Controls nest inside controls to mirror the actual DOM or component structure.
12
12
-**Relative Locators & Reusability**: Because controls nest, locators are chained under the hood (`parent.locator().getByTestId(...)`). Selectors only need to be unique *within their parent component*, massively improving reusability. Instead of `data-testid="checkout-page-cart-item-remove-button"`, you just use `data-testid="Remove"`.
13
13
-**Lazy over eager**: Locator chains rebuild dynamically only when accessed, ensuring resilience against dynamic DOM changes and re-renders.
14
14
-**Playwright Best Practices Embedded**: Deep support for user-facing attributes (`getByRole`, `getByText`, etc.) natively via decorators, with web-first assertions built-in.
15
15
16
16
### The Control Graph
17
-
Controls compose into a hierarchical structure mirroring the DOM:
17
+
Controls compose into a hierarchical structure mirroring the DOM or your components structure:
*Note: This library heavily relies on the ECMAScript standard `accessor` keyword (stable in TypeScript 5.0+). Make sure your `tsconfig.json` targets an appropriate environment (`"target": "ES2015"` or higher) or ensures decorators are supported.*
@@ -56,54 +61,71 @@ When a class extends `PageObject`, it inherits a rich set of built-in methods fo
56
61
57
62
Like raw Playwright, these actions automatically wait for the element to become actionable (visible, enabled, stable).
58
63
59
-
-`.click(options?)`: Clicks the element.
60
-
-`.dblclick(options?)`: Double-clicks the element.
61
-
-`.hover(options?)`: Hovers over the element.
62
-
-`.fill(value, options?)`: Fills the input with the given value.
63
-
-`.clear(options?)`: Clears the input value.
64
-
-`.check(options?)`: Checks a checkbox or radio button.
65
-
-`.uncheck(options?)`: Unchecks a checkbox.
66
-
-`.press(key, options?)`: Presses a key (e.g., `Enter`, `Tab`) on the element.
64
+
| Method | Description |
65
+
|--------|-------------|
66
+
|`.click(options?)`| Clicks the element. |
67
+
|`.dblclick(options?)`| Double-clicks the element. |
68
+
|`.hover(options?)`| Hovers over the element. |
69
+
|`.fill(value, options?)`| Fills the input with the given value. |
70
+
|`.clear(options?)`| Clears the input value. |
71
+
|`.check(options?)`| Checks a checkbox or radio button. |
72
+
|`.uncheck(options?)`| Unchecks a checkbox. |
73
+
|`.press(key, options?)`| Presses a key (e.g., `Enter`, `Tab`) on the element. |
67
74
68
75
### Waits
69
-
-`.waitVisible()`: Waits for the element to become visible.
70
-
-`.waitHidden()`: Waits for the element to become hidden.
71
-
-`.waitText(text)`: Waits for the element to have the given text (string or regex).
72
-
-`.waitValue(value)`: Waits for the element to have the given value.
73
-
-`.waitNoValue()`: Waits for the element to have no value.
74
-
-`.waitCount(count)`: Waits for the locator to resolve to the given count.
75
-
-`.waitChecked()`: Waits for a checkbox/radio to be checked.
76
-
-`.waitUnChecked()`: Waits for a checkbox/radio to be unchecked.
77
-
-`.waitProp(name, value)`: Waits for a React/Vue prop (data attribute) to equal the given value.
78
-
-`.waitPropAbsence(name, value)`: Waits for a React/Vue prop (data attribute) to NOT equal the given value.
76
+
77
+
| Method | Description |
78
+
|--------|-------------|
79
+
|`.waitVisible()`| Waits for the element to become visible. |
80
+
|`.waitHidden()`| Waits for the element to become hidden. |
81
+
|`.waitText(text)`| Waits for the element to have the given text (string or regex). |
82
+
|`.waitValue(value)`| Waits for the element to have the given value. |
83
+
|`.waitNoValue()`| Waits for the element to have no value. |
84
+
|`.waitCount(count)`| Waits for the locator to resolve to the given count. |
85
+
|`.waitChecked()`| Waits for a checkbox/radio to be checked. |
86
+
|`.waitUnChecked()`| Waits for a checkbox/radio to be unchecked. |
87
+
|`.waitProp(name, value)`| Waits for a React/Vue prop (data attribute) to equal the given value. |
88
+
|`.waitPropAbsence(name, value)`| Waits for a React/Vue prop (data attribute) to NOT equal the given value. |
79
89
80
90
### Assertions
81
91
82
92
Provides native Playwright assertions securely tied to the underlying locator.
83
-
-`.expect()`: Returns a Playwright expect assertion for this locator (e.g., `await myControl.expect().toBeEnabled()`).
84
-
-`.expect({ soft: true })`: Support for soft assertions that do not fail the test immediately.
93
+
94
+
| Method | Description |
95
+
|--------|-------------|
96
+
|`.expect()`| Returns a Playwright expect assertion for this locator (e.g., `await myControl.expect().toBeEnabled()`). |
97
+
|`.expect({ soft: true })`| Support for soft assertions that do not fail the test immediately. |
85
98
86
99
## 📚 Comprehensive API Reference: `ListPageObject`
87
100
88
101
Manage collections of elements effortlessly with `ListPageObject`.
89
102
90
103
### The `.items` Proxy
91
-
-**Array-like access**: Access specific items directly via index: `list.items[0]`
92
-
-**Async iteration**: Iterate over all matching items easily: `for await (const item of list.items) { ... }`
104
+
105
+
| Feature | Description |
106
+
|---------|-------------|
107
+
| Array-like access | Access specific items directly via index: `list.items[0]`|
108
+
| Async iteration | Iterate over all matching items easily: `for await (const item of list.items) { ... }`|
93
109
94
110
### Retrieval & Filtering
95
-
-`.first()`: Returns the first item (index 0).
96
-
-`.last()`: Returns the last item (index -1).
97
-
-`.getItemByIndex(index)`: Returns the item at the given index.
98
-
-`.filter(options)`: Returns items matching the given Playwright filter options.
99
-
-`.filterByText(text)`: Returns items containing the given text.
100
-
-`.filterByTestId(id)`: Returns items that contain an element with the given test id.
101
-
-`.getItemByText(text)`: Returns the specific item containing the given text.
102
-
-`.getItemByRole(role, options?)`: Returns the specific item matching the given ARIA role.
111
+
112
+
| Method | Description |
113
+
|--------|-------------|
114
+
|`.first()`| Returns the first item (index 0). |
115
+
|`.last()`| Returns the last item (index -1). |
116
+
|`.getItemByIndex(index)`| Returns the item at the given index. |
117
+
|`.filter(options)`| Returns items matching the given Playwright filter options. |
118
+
|`.filterByText(text)`| Returns items containing the given text. |
119
+
|`.filterByTestId(id)`| Returns items that contain an element with the given test id. |
120
+
|`.getItemByText(text)`| Returns the specific item containing the given text. |
121
+
|`.getItemByRole(role, options?)`| Returns the specific item matching the given ARIA role. |
103
122
104
123
### Utilities
105
-
-`.count()`: Returns the total number of items in the list.
106
-
-`.getAll()`: Returns all items as an array of page objects.
124
+
125
+
| Method | Description |
126
+
|--------|-------------|
127
+
|`.count()`| Returns the total number of items in the list. |
128
+
|`.getAll()`| Returns all items as an array of page objects. |
107
129
108
130
## 🏷️ Decorators Cheat Sheet
109
131
@@ -113,31 +135,43 @@ The library provides 1-to-1 mappings with Playwright's native locator methods.
113
135
Each strategy has a `@Selector...` variant for nested controls and a `@RootSelector...` variant for top-level pages.
114
136
115
137
### Root Locators (Top-level entry points)
138
+
116
139
Used on classes to define the base locator for a page or top-level component.
0 commit comments