docs: add custom test id attribute snippet (#18210)

Fixes https://github.com/microsoft/playwright/issues/18203
This commit is contained in:
Pavel Feldman 2022-10-20 13:54:57 -04:00 committed by GitHub
parent c4d417e04a
commit 05678c9986
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 0 deletions

View file

@ -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.

View file

@ -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;