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
Nested `PageObject` subclasses use the default constructor shape `(root?: Locator, selector?: SelectorType)`. If a nested subclass needs custom constructor arguments, implement `cloneWithContext()` so it can rebuild itself with the new `root` and `selector`.
251
+
247
252
Wait helpers:
248
253
249
254
| Method | Description |
@@ -277,8 +282,12 @@ Useful APIs:
277
282
-`list.items.at(-1)`
278
283
-`for await (const item of list.items) { ... }`
279
284
-`await list.count()`
280
-
-`await list.first()`
281
-
-`await list.filterByText("Apple")`
285
+
-`list.first()`
286
+
-`list.second()`
287
+
-`list.filterByText("Apple")`
288
+
-`list.filterByText("Apple").first()`
289
+
290
+
Indexing and search helpers such as `first()`, `second()`, `at()`, `getItemByText()`, and `getItemByRole()` return a single item page object. Filter helpers such as `filter()`, `filterByText()`, and `filterByTestId()` return a narrower `ListPageObject`, so chain `.first()` or `.at(...)` when you need one matched item.
Copy file name to clipboardExpand all lines: skills/playwright-page-object/SKILL.md
+7-2Lines changed: 7 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,8 @@ When entering a codebase, detect these first:
47
47
-`createFixtures(...)`
48
48
- manual `new MyPage(page)`
49
49
4. Custom nested `PageObject` constructors:
50
-
- if a nested `PageObject` subclass does not use the default constructor shape, it must implement `cloneWithContext()`
50
+
- the default nested `PageObject` constructor shape is `(root?: Locator, selector?: SelectorType)`
51
+
- if a nested `PageObject` subclass does not use that shape, it must implement `cloneWithContext()`
51
52
52
53
Preserve the user's current style. Do not force a migration to the built-in POM if the codebase already uses plain classes or external controls successfully.
53
54
@@ -107,7 +108,7 @@ class CheckoutPage extends RootPageObject {}
107
108
- the user wants built-in waits or `.expect()`
108
109
- the control is reused compositionally under selector decorators
109
110
110
-
If a nested `PageObject` subclass adds a custom constructor, either keep the default constructor shape or implement `cloneWithContext()` explicitly.
111
+
Nested `PageObject` instances derive `page` from their current root context. If a nested `PageObject` subclass adds a custom constructor, either keep the default `(root?: Locator, selector?: SelectorType)` shape or implement `cloneWithContext()` explicitly.
111
112
112
113
### Choose `ListPageObject` when
113
114
@@ -191,8 +192,11 @@ class CheckoutPage extends RootPageObject {
191
192
When using the built-in classes:
192
193
193
194
- actions go through `control.$`
195
+
- nested `PageObject` instances derive `page` from `root.page()`
-`ListPageObject` indexing/search helpers such as `first()`, `second()`, `at()`, and `getItemByText()` return one item page object
199
+
-`ListPageObject` filter helpers such as `filter()`, `filterByText()`, and `filterByTestId()` return a narrower `ListPageObject`, so chain `.first()` or `.at(...)` when one item is needed
0 commit comments