chore: expose testIdAttributeName via Selector.testIdAttributeName
This commit is contained in:
parent
718bd9b35f
commit
d5c4b496b9
|
|
@ -248,3 +248,8 @@ Defines custom attribute name to be used in [`method: Page.getByTestId`]. `data-
|
|||
- `attributeName` <[string]>
|
||||
|
||||
Test id attribute name.
|
||||
|
||||
## method: Selectors.testIdAttributeName
|
||||
* since: v1.48
|
||||
|
||||
Return the current Test id attribute name.
|
||||
|
|
@ -607,6 +607,26 @@ page.get_by_test_id("directions").click()
|
|||
await page.GetByTestId("directions").ClickAsync();
|
||||
```
|
||||
|
||||
#### Get the current test id attribute name
|
||||
|
||||
Return the current test id attribute name, this will default to `data-testid`, if not updated using your test config or set using [`method: Selectors.setTestIdAttribute`].
|
||||
|
||||
```java
|
||||
playwright.selectors().testIdAttributeName();
|
||||
```
|
||||
|
||||
```python async
|
||||
playwright.selectors.test_id_attribute_name()
|
||||
```
|
||||
|
||||
```python sync
|
||||
playwright.selectors.test_id_attribute_name()
|
||||
```
|
||||
|
||||
```csharp
|
||||
playwright.Selectors.TestIdAttributeName();
|
||||
```
|
||||
|
||||
### Locate by CSS or XPath
|
||||
|
||||
If you absolutely must use CSS or XPath locators, you can use [`method: Page.locator`] to create a locator that takes a selector describing how to find an element in the page. Playwright supports CSS and XPath selectors, and auto-detects them if you omit `css=` or `xpath=` prefix.
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ export class Selectors implements api.Selectors {
|
|||
channel._channel.setTestIdAttributeName({ testIdAttributeName: attributeName }).catch(() => {});
|
||||
}
|
||||
|
||||
testIdAttributeName = () => testIdAttributeName();
|
||||
|
||||
_addChannel(channel: SelectorsOwner) {
|
||||
this._channels.add(channel);
|
||||
for (const params of this._registrations) {
|
||||
|
|
|
|||
5
packages/playwright-core/types/types.d.ts
vendored
5
packages/playwright-core/types/types.d.ts
vendored
|
|
@ -19895,6 +19895,11 @@ export interface Selectors {
|
|||
* @param attributeName Test id attribute name.
|
||||
*/
|
||||
setTestIdAttribute(attributeName: string): void;
|
||||
|
||||
/**
|
||||
* Return the current Test id attribute name.
|
||||
*/
|
||||
testIdAttributeName(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -596,4 +596,9 @@ it.describe('selector generator', () => {
|
|||
`span >> nth=1`,
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return the current testIdAttributeName', async ({ playwright }) => {
|
||||
playwright.selectors.setTestIdAttribute('data-custom-id');
|
||||
expect(playwright.selectors.testIdAttributeName()).toEqual('data-custom-id');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue