From 05678c998683ce98816db66235c4ed9bde3beac4 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Thu, 20 Oct 2022 13:54:57 -0400 Subject: [PATCH] docs: add custom test id attribute snippet (#18210) Fixes https://github.com/microsoft/playwright/issues/18203 --- docs/src/api/params.md | 7 +++++ packages/playwright-core/types/types.d.ts | 32 +++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/docs/src/api/params.md b/docs/src/api/params.md index fbcff42573..872e6439f7 100644 --- a/docs/src/api/params.md +++ b/docs/src/api/params.md @@ -1176,6 +1176,13 @@ Locator is resolved to the element immediately before performing an action, so a Locate element by the test id. By default, the `data-testid` attribute is used as a test id. Use [`method: Selectors.setTestIdAttribute`] to configure a different test id attribute if necessary. +```js +// Set custom test id attribute from @playwright/test config: +use: { + testIdAttribute: 'data-pw' +} +``` + ## template-locator-get-by-text Allows locating elements that contain given text. diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts index 4117c0635f..0a39bb0b31 100644 --- a/packages/playwright-core/types/types.d.ts +++ b/packages/playwright-core/types/types.d.ts @@ -2581,6 +2581,14 @@ export interface Page { * Locate element by the test id. By default, the `data-testid` attribute is used as a test id. Use * [selectors.setTestIdAttribute(attributeName)](https://playwright.dev/docs/api/class-selectors#selectors-set-test-id-attribute) * to configure a different test id attribute if necessary. + * + * ```js + * // Set custom test id attribute from @playwright/test config: + * use: { + * testIdAttribute: 'data-pw' + * } + * ``` + * * @param testId Id to locate the element by. */ getByTestId(testId: string): Locator; @@ -5681,6 +5689,14 @@ export interface Frame { * Locate element by the test id. By default, the `data-testid` attribute is used as a test id. Use * [selectors.setTestIdAttribute(attributeName)](https://playwright.dev/docs/api/class-selectors#selectors-set-test-id-attribute) * to configure a different test id attribute if necessary. + * + * ```js + * // Set custom test id attribute from @playwright/test config: + * use: { + * testIdAttribute: 'data-pw' + * } + * ``` + * * @param testId Id to locate the element by. */ getByTestId(testId: string): Locator; @@ -10125,6 +10141,14 @@ export interface Locator { * Locate element by the test id. By default, the `data-testid` attribute is used as a test id. Use * [selectors.setTestIdAttribute(attributeName)](https://playwright.dev/docs/api/class-selectors#selectors-set-test-id-attribute) * to configure a different test id attribute if necessary. + * + * ```js + * // Set custom test id attribute from @playwright/test config: + * use: { + * testIdAttribute: 'data-pw' + * } + * ``` + * * @param testId Id to locate the element by. */ getByTestId(testId: string): Locator; @@ -15392,6 +15416,14 @@ export interface FrameLocator { * Locate element by the test id. By default, the `data-testid` attribute is used as a test id. Use * [selectors.setTestIdAttribute(attributeName)](https://playwright.dev/docs/api/class-selectors#selectors-set-test-id-attribute) * to configure a different test id attribute if necessary. + * + * ```js + * // Set custom test id attribute from @playwright/test config: + * use: { + * testIdAttribute: 'data-pw' + * } + * ``` + * * @param testId Id to locate the element by. */ getByTestId(testId: string): Locator;