Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion docs/src/api/class-locator.md
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ Locator description.
* since: v1.57
- returns: <[null]|[string]>

Returns locator description previously set with [`method: Locator.describe`]. Returns `null` if no custom description has been set. Prefer `Locator.toString()` for a human-readable representation, as it uses the description when available.
Returns locator description previously set with [`method: Locator.describe`]. Returns `null` if no custom description has been set. Prefer [`method: Locator.toString`] for a human-readable representation, as it uses the description when available.

**Usage**

Expand Down Expand Up @@ -2534,6 +2534,13 @@ If you need to assert text on the page, prefer [`method: LocatorAssertions.toHav
### option: Locator.textContent.timeout = %%-input-timeout-js-%%
* since: v1.14

## method: Locator.toString
* since: v1.57
* langs: js
- returns: <[String]>

Returns a human-readable representation of the locator, using the [`method: Locator.description`] if one exists; otherwise, it generates a string based on the locator's selector.

## async method: Locator.type
* since: v1.14
* deprecated: In most cases, you should use [`method: Locator.fill`] instead. You only need to press keys one by one if there is special keyboard handling on the page - in this case use [`method: Locator.pressSequentially`].
Expand Down
2 changes: 1 addition & 1 deletion docs/src/release-notes-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ After 3 years of being deprecated, we removed `page.accessibility` from our API.

- New property [`property: TestConfig.tag`] adds a tag to all tests in this run. This is useful when using [merge-reports](./test-sharding.md#merging-reports-from-multiple-shards).
- [`event: Worker.console`] event is emitted when JavaScript within the worker calls one of console API methods, e.g. console.log or console.dir. [`method: Worker.waitForEvent`] can be used to wait for it.
- [`method: Locator.description`] returns locator description previously set with [`method: Locator.describe`], and `Locator.toString()` now uses the description when available.
- [`method: Locator.description`] returns locator description previously set with [`method: Locator.describe`], and [`method: Locator.toString`] now uses the description when available.
- New option [`option: Locator.click.steps`] in [`method: Locator.click`] and [`method: Locator.dragTo`] that configures the number of `mousemove` events emitted while moving the mouse pointer to the target element.
- Network requests issued by [Service Workers](./service-workers.md#network-events-and-routing) are now reported and can be routed through the [BrowserContext](./api/class-browsercontext.md), only in Chromium. You can opt out using the `PLAYWRIGHT_DISABLE_SERVICE_WORKER_NETWORK` environment variable.
- Console messages from Service Workers are dispatched through [`event: Worker.console`]. You can opt out of this using the `PLAYWRIGHT_DISABLE_SERVICE_WORKER_CONSOLE` environment variable.
Expand Down
11 changes: 9 additions & 2 deletions packages/playwright-client/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12644,6 +12644,12 @@ export interface Locator {
elementHandle(options?: {
timeout?: number;
}): Promise<null|ElementHandle<SVGElement | HTMLElement>>;
/**
* Returns a human-readable representation of the locator, using the
* [locator.description()](https://playwright.dev/docs/api/class-locator#locator-description) if one exists;
* otherwise, it generates a string based on the locator's selector.
*/
toString(): string;
/**
* When the locator points to a list of elements, this returns an array of locators, pointing to their respective
* elements.
Expand Down Expand Up @@ -13198,8 +13204,9 @@ export interface Locator {
/**
* Returns locator description previously set with
* [locator.describe(description)](https://playwright.dev/docs/api/class-locator#locator-describe). Returns `null` if
* no custom description has been set. Prefer `Locator.toString()` for a human-readable representation, as it uses the
* description when available.
* no custom description has been set. Prefer
* [locator.toString()](https://playwright.dev/docs/api/class-locator#locator-to-string) for a human-readable
* representation, as it uses the description when available.
*
* **Usage**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface LocatorFactory {
chainLocators(locators: string[]): string;
}

export function asLocatorDescription(lang: Language, selector: string): string | undefined {
export function asLocatorDescription(lang: Language, selector: string): string {
try {
const parsed = parseSelector(selector);
const customDescription = parseCustomDescription(parsed);
Expand Down
11 changes: 9 additions & 2 deletions packages/playwright-core/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12644,6 +12644,12 @@ export interface Locator {
elementHandle(options?: {
timeout?: number;
}): Promise<null|ElementHandle<SVGElement | HTMLElement>>;
/**
* Returns a human-readable representation of the locator, using the
* [locator.description()](https://playwright.dev/docs/api/class-locator#locator-description) if one exists;
* otherwise, it generates a string based on the locator’s selector.
*/
toString(): string;
/**
* When the locator points to a list of elements, this returns an array of locators, pointing to their respective
* elements.
Expand Down Expand Up @@ -13198,8 +13204,9 @@ export interface Locator {
/**
* Returns locator description previously set with
* [locator.describe(description)](https://playwright.dev/docs/api/class-locator#locator-describe). Returns `null` if
* no custom description has been set. Prefer `Locator.toString()` for a human-readable representation, as it uses the
* description when available.
* no custom description has been set. Prefer
* [locator.toString()](https://playwright.dev/docs/api/class-locator#locator-to-string) for a human-readable
* representation, as it uses the description when available.
*
* **Usage**
*
Expand Down
1 change: 1 addition & 0 deletions utils/generate_types/overrides.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export interface Locator {
elementHandle(options?: {
timeout?: number;
}): Promise<null|ElementHandle<SVGElement | HTMLElement>>;
toString(): string;
}

export interface BrowserType<Unused = {}> {
Expand Down