From 2a8d6a8207b2160dfdf9f4c755b3e548e1a9719e Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Fri, 29 Sep 2023 10:52:20 -0700 Subject: [PATCH] docs: encourage using `expect()` instead of getters like `textContent()` (#27362) --- docs/src/api/class-locator.md | 52 +++++++++++++++++++++++ packages/playwright-core/types/types.d.ts | 52 +++++++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/docs/src/api/class-locator.md b/docs/src/api/class-locator.md index 3def5f0e5d..177b75be46 100644 --- a/docs/src/api/class-locator.md +++ b/docs/src/api/class-locator.md @@ -53,6 +53,10 @@ foreach (var li in await page.GetByRole("listitem").AllAsync()) Returns an array of `node.innerText` values for all matching nodes. +:::caution Asserting text +If you need to assert text on the page, prefer [`method: LocatorAssertions.toHaveText`] with [`option: useInnerText`] option to avoid flakiness. See [assertions guide](../test-assertions.md) for more details. +::: + **Usage** ```js @@ -81,6 +85,10 @@ var texts = await page.GetByRole(AriaRole.Link).AllInnerTextsAsync(); Returns an array of `node.textContent` values for all matching nodes. +:::caution Asserting text +If you need to assert text on the page, prefer [`method: LocatorAssertions.toHaveText`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details. +::: + **Usage** ```js @@ -435,6 +443,10 @@ await page.Locator("canvas").ClickAsync(new() { Returns the number of elements matching the locator. +:::caution Asserting count +If you need to assert the number of elements on the page, prefer [`method: LocatorAssertions.toHaveCount`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details. +::: + **Usage** ```js @@ -1059,6 +1071,10 @@ await locator.ClickAsync(); Returns the matching element's attribute value. +:::caution Asserting attributes +If you need to assert an element's attribute, prefer [`method: LocatorAssertions.toHaveAttribute`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details. +::: + ### param: Locator.getAttribute.name * since: v1.14 - `name` <[string]> @@ -1227,6 +1243,10 @@ Returns the [`element.innerHTML`](https://developer.mozilla.org/en-US/docs/Web/A Returns the [`element.innerText`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText). +:::caution Asserting text +If you need to assert text on the page, prefer [`method: LocatorAssertions.toHaveText`] with [`option: useInnerText`] option to avoid flakiness. See [assertions guide](../test-assertions.md) for more details. +::: + ### option: Locator.innerText.timeout = %%-input-timeout-%% * since: v1.14 @@ -1239,6 +1259,10 @@ Returns the [`element.innerText`](https://developer.mozilla.org/en-US/docs/Web/A Returns the value for the matching `` or `