diff --git a/docs/api/puppeteer.locator.filter.md b/docs/api/puppeteer.locator.filter.md new file mode 100644 index 00000000..da005627 --- /dev/null +++ b/docs/api/puppeteer.locator.filter.md @@ -0,0 +1,27 @@ +--- +sidebar_label: Locator.filter +--- + +# Locator.filter() method + +Creates an expectation that is evaluated against located values. + +If the expectations do not match, then the locator will retry. + +#### Signature: + +```typescript +class Locator { + filter(predicate: Predicate): Locator; +} +``` + +## Parameters + +| Parameter | Type | Description | +| --------- | ------------------------------------------------- | ----------- | +| predicate | [Predicate](./puppeteer.predicate.md)<T, S> | | + +**Returns:** + +[Locator](./puppeteer.locator.md)<S> diff --git a/docs/api/puppeteer.locator.md b/docs/api/puppeteer.locator.md index ddd17299..0eb49ab7 100644 --- a/docs/api/puppeteer.locator.md +++ b/docs/api/puppeteer.locator.md @@ -26,6 +26,7 @@ export declare abstract class Locator extends EventEmitter | ------------------------------------------------------------------------------------------------------ | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | [click(this, options)](./puppeteer.locator.click.md) | | | | [fill(this, value, options)](./puppeteer.locator.fill.md) | | Fills out the input identified by the locator using the provided value. The type of the input is determined at runtime and the appropriate fill-out method is chosen based on the type. contenteditable, selector, inputs are supported. | +| [filter(predicate)](./puppeteer.locator.filter.md) | |

Creates an expectation that is evaluated against located values.

If the expectations do not match, then the locator will retry.

| | [hover(this, options)](./puppeteer.locator.hover.md) | | | | [map(mapper)](./puppeteer.locator.map.md) | | Maps the locator using the provided mapper. | | [off(eventName, handler)](./puppeteer.locator.off.md) | | | diff --git a/packages/puppeteer-core/src/api/locators/ExpectedLocator.ts b/packages/puppeteer-core/src/api/locators/FilteredLocator.ts similarity index 96% rename from packages/puppeteer-core/src/api/locators/ExpectedLocator.ts rename to packages/puppeteer-core/src/api/locators/FilteredLocator.ts index 75056c56..b9d9ebef 100644 --- a/packages/puppeteer-core/src/api/locators/ExpectedLocator.ts +++ b/packages/puppeteer-core/src/api/locators/FilteredLocator.ts @@ -37,7 +37,7 @@ export type Predicate = /** * @internal */ -export class ExpectedLocator extends DelegatedLocator< +export class FilteredLocator extends DelegatedLocator< From, To > { diff --git a/packages/puppeteer-core/src/api/locators/Locator.ts b/packages/puppeteer-core/src/api/locators/Locator.ts index b454944e..c65901f9 100644 --- a/packages/puppeteer-core/src/api/locators/Locator.ts +++ b/packages/puppeteer-core/src/api/locators/Locator.ts @@ -47,7 +47,7 @@ import {BoundingBox, ClickOptions, ElementHandle} from '../ElementHandle.js'; import { Action, AwaitedLocator, - ExpectedLocator, + FilteredLocator, MappedLocator, Mapper, Predicate, @@ -671,10 +671,10 @@ export abstract class Locator extends EventEmitter { * * If the expectations do not match, then the locator will retry. * - * @internal + * @public */ - expect(predicate: Predicate): Locator { - return new ExpectedLocator(this, predicate); + filter(predicate: Predicate): Locator { + return new FilteredLocator(this, predicate); } click( diff --git a/packages/puppeteer-core/src/api/locators/locators.ts b/packages/puppeteer-core/src/api/locators/locators.ts index 77e5fc83..c71400f4 100644 --- a/packages/puppeteer-core/src/api/locators/locators.ts +++ b/packages/puppeteer-core/src/api/locators/locators.ts @@ -16,7 +16,7 @@ export * from './Locator.js'; export * from './NodeLocator.js'; -export * from './ExpectedLocator.js'; +export * from './FilteredLocator.js'; export * from './RaceLocator.js'; export * from './DelegatedLocator.js'; export * from './MappedLocator.js'; diff --git a/test/src/locator.spec.ts b/test/src/locator.spec.ts index 7dd7d73f..ef5b9c45 100644 --- a/test/src/locator.spec.ts +++ b/test/src/locator.spec.ts @@ -587,7 +587,7 @@ describe('Locator', function () { await page.setContent(`
test
`); const result = page .locator('::-p-text(test)') - .expect(element => { + .filter(element => { return element.getAttribute('clickable') !== null; }) .map(element => { @@ -601,7 +601,7 @@ describe('Locator', function () { }); }); - describe('Locator.prototype.expect', () => { + describe('Locator.prototype.filter', () => { it('should resolve as soon as the predicate matches', async () => { const clock = sinon.useFakeTimers({ shouldClearNativeTimers: true, @@ -612,10 +612,10 @@ describe('Locator', function () { const result = page .locator('::-p-text(test)') .setTimeout(5000) - .expect(async element => { + .filter(async element => { return element.getAttribute('clickable') === 'true'; }) - .expect(element => { + .filter(element => { return element.getAttribute('clickable') === 'true'; }) .hover();