Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
292 changes: 0 additions & 292 deletions docs/custom-locators-playwright.md

This file was deleted.

12 changes: 0 additions & 12 deletions docs/helpers/Playwright.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,13 @@ Type: [object][6]
* `highlightElement` **[boolean][28]?** highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
* `recordHar` **[object][6]?** record HAR and will be saved to `output/har`. See more of [HAR options][3].
* `testIdAttribute` **[string][9]?** locate elements based on the testIdAttribute. See more of [locate by test id][51].
* `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}"]`) } }`
* `storageState` **([string][9] | [object][6])?** Playwright storage state (path to JSON file or object)
passed directly to `browser.newContext`.
If a Scenario is declared with a `cookies` option (e.g. `Scenario('name', { cookies: [...] }, fn)`),
those cookies are used instead and the configured `storageState` is ignored (no merge).
May include session cookies, auth tokens, localStorage and (if captured with
`grabStorageState({ indexedDB: true })`) IndexedDB data; treat as sensitive and do not commit.

## createCustomSelectorEngine

Creates a Playwright selector engine factory for a custom locator strategy.

### Parameters

* `name` **[string][9]** Strategy name for error messages
* `func` **[Function][22]** The locator function (selector, root) => Element|Element[]

Returns **[Function][22]** Selector engine factory

## handleRoleLocator

Handles role locator objects by converting them to Playwright's getByRole() API
Expand Down
46 changes: 0 additions & 46 deletions docs/playwright.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,52 +131,6 @@ I.fillField({ name: 'user[email]' }, 'miles@davis.com')
I.seeElement({ xpath: '//body/header' })
```

### Custom Locator Strategies

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.

To use custom locator strategies, configure them in your `codecept.conf.js`:

```js
exports.config = {
helpers: {
Playwright: {
url: 'http://localhost',
browser: 'chromium',
customLocatorStrategies: {
byRole: (selector, root) => {
return root.querySelector(`[role="${selector}"]`);
},
byTestId: (selector, root) => {
return root.querySelector(`[data-testid="${selector}"]`);
},
byDataQa: (selector, root) => {
const elements = root.querySelectorAll(`[data-qa="${selector}"]`);
return Array.from(elements); // Return array for multiple elements
}
}
}
}
}
```

Once configured, you can use these custom locator strategies in your tests:

```js
I.click({byRole: 'button'}); // Find by role attribute
I.see('Welcome', {byTestId: 'title'}); // Find by data-testid
I.fillField({byDataQa: 'email'}, 'test@example.com');
```

**Custom Locator Function Guidelines:**
- Functions receive `(selector, root)` parameters where `selector` is the value and `root` is the DOM context
- Return a single DOM element for finding the first match
- Return an array of DOM elements for finding all matches
- Return `null` or empty array if no elements found
- Functions execute in the browser context, so only browser APIs are available

This feature provides the same functionality as WebDriver's custom locator strategies but leverages Playwright's native selector engine system.

### Interactive Pause

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