Skip to content

feat: Add extendLocator to extend locators with custom properties and functions - #51

Merged
foxable merged 2 commits into
mainfrom
feat/extend-locator
Oct 5, 2026
Merged

foxable merged 2 commits into
mainfrom
feat/extend-locator

Conversation

@foxable

@foxable foxable commented Oct 2, 2026

Copy link
Copy Markdown
Member

Adds extendLocator, which extends a Playwright Locator with custom properties and functions while retaining the full Locator API. The extended locator can still be used for actions, combined with other locators via and()/or() and passed to expect. Overriding members of Locator is rejected at the type level. The new ExtendedLocator type is exported as well.

Example

import { extendLocator, roleLocators } from "@cronn/playwright-utils";
import { expect, test } from "@playwright/test";

test("selects a date", async ({ page }) => {
  const { textbox } = roleLocators(page);

  const datePicker = extendLocator(textbox("Date"), (locator) => ({
    async selectDate(date: Date) {
      await locator.fill(date.toISOString().slice(0, 10));
    },
  }));

  await datePicker.selectDate(new Date("2026-10-02"));

  await expect(datePicker).toHaveValue("2026-10-02");
});

@foxable foxable self-assigned this Oct 2, 2026
@changeset-bot

changeset-bot Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c5f1390

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cronn/playwright-utils Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@foxable
foxable force-pushed the feat/extend-locator branch from 7892fca to c5f1390 Compare October 5, 2026 13:17
@foxable
foxable merged commit 9113974 into main Oct 5, 2026
3 checks passed
@foxable
foxable deleted the feat/extend-locator branch October 5, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants