Skip to content

Commit ed3bcba

Browse files
committed
remove Custom Locator Strategy from playwright
1 parent 9cca480 commit ed3bcba

File tree

11 files changed

+15
-1348
lines changed

11 files changed

+15
-1348
lines changed

docs/custom-locators-playwright.md

Lines changed: 0 additions & 292 deletions
This file was deleted.

docs/helpers/Playwright.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,13 @@ Type: [object][6]
8080
* `highlightElement` **[boolean][28]?** highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
8181
* `recordHar` **[object][6]?** record HAR and will be saved to `output/har`. See more of [HAR options][3].
8282
* `testIdAttribute` **[string][9]?** locate elements based on the testIdAttribute. See more of [locate by test id][51].
83-
* `customLocatorStrategies` **[object][6]?** custom locator strategies. An object with keys as strategy names and values as JavaScript functions. Example: `{ byRole: (selector, root) => { return root.querySelector(`[role="${selector}"]`) } }`
8483
* `storageState` **([string][9] | [object][6])?** Playwright storage state (path to JSON file or object)
8584
passed directly to `browser.newContext`.
8685
If a Scenario is declared with a `cookies` option (e.g. `Scenario('name', { cookies: [...] }, fn)`),
8786
those cookies are used instead and the configured `storageState` is ignored (no merge).
8887
May include session cookies, auth tokens, localStorage and (if captured with
8988
`grabStorageState({ indexedDB: true })`) IndexedDB data; treat as sensitive and do not commit.
9089

91-
## createCustomSelectorEngine
92-
93-
Creates a Playwright selector engine factory for a custom locator strategy.
94-
95-
### Parameters
96-
97-
* `name` **[string][9]** Strategy name for error messages
98-
* `func` **[Function][22]** The locator function (selector, root) => Element|Element[]
99-
100-
Returns **[Function][22]** Selector engine factory
101-
10290
## handleRoleLocator
10391

10492
Handles role locator objects by converting them to Playwright's getByRole() API

docs/playwright.md

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -131,52 +131,6 @@ I.fillField({ name: 'user[email]' }, 'miles@davis.com')
131131
I.seeElement({ xpath: '//body/header' })
132132
```
133133

134-
### Custom Locator Strategies
135-
136-
CodeceptJS with Playwright supports custom locator strategies, allowing you to define your own element finding logic. Custom locator strategies are JavaScript functions that receive a selector value and return DOM elements.
137-
138-
To use custom locator strategies, configure them in your `codecept.conf.js`:
139-
140-
```js
141-
exports.config = {
142-
helpers: {
143-
Playwright: {
144-
url: 'http://localhost',
145-
browser: 'chromium',
146-
customLocatorStrategies: {
147-
byRole: (selector, root) => {
148-
return root.querySelector(`[role="${selector}"]`);
149-
},
150-
byTestId: (selector, root) => {
151-
return root.querySelector(`[data-testid="${selector}"]`);
152-
},
153-
byDataQa: (selector, root) => {
154-
const elements = root.querySelectorAll(`[data-qa="${selector}"]`);
155-
return Array.from(elements); // Return array for multiple elements
156-
}
157-
}
158-
}
159-
}
160-
}
161-
```
162-
163-
Once configured, you can use these custom locator strategies in your tests:
164-
165-
```js
166-
I.click({byRole: 'button'}); // Find by role attribute
167-
I.see('Welcome', {byTestId: 'title'}); // Find by data-testid
168-
I.fillField({byDataQa: 'email'}, 'test@example.com');
169-
```
170-
171-
**Custom Locator Function Guidelines:**
172-
- Functions receive `(selector, root)` parameters where `selector` is the value and `root` is the DOM context
173-
- Return a single DOM element for finding the first match
174-
- Return an array of DOM elements for finding all matches
175-
- Return `null` or empty array if no elements found
176-
- Functions execute in the browser context, so only browser APIs are available
177-
178-
This feature provides the same functionality as WebDriver's custom locator strategies but leverages Playwright's native selector engine system.
179-
180134
### Interactive Pause
181135

182136
It's easy to start writing a test if you use [interactive pause](/basics#debug). Just open a web page and pause execution.

0 commit comments

Comments
 (0)