Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test: add 'getByTestId with custom testId should work' (#17966)

Max Schmitt70258d9c49b7
diff --git a/tests/page/selectors-get-by.spec.ts b/tests/page/selectors-get-by.spec.ts
index dba7978592..a54cbe237b 100644
--- a/tests/page/selectors-get-by.spec.ts
+++ b/tests/page/selectors-get-by.spec.ts
@@ -23,6 +23,14 @@ it('getByTestId should work', async ({ page }) => {
await expect(page.locator('div').getByTestId('Hello')).toHaveText('Hello world');
});
+it('getByTestId with custom testId should work', async ({ page, playwright }) => {
+ await page.setContent('<div><div data-my-custom-testid="Hello">Hello world</div></div>');
+ playwright.selectors.setTestIdAttribute('data-my-custom-testid');
+ await expect(page.getByTestId('Hello')).toHaveText('Hello world');
+ await expect(page.mainFrame().getByTestId('Hello')).toHaveText('Hello world');
+ await expect(page.locator('div').getByTestId('Hello')).toHaveText('Hello world');
+});
+
it('getByTestId should escape id', async ({ page }) => {
await page.setContent(`<div><div data-testid='He"llo'>Hello world</div></div>`);
await expect(page.getByTestId('He"llo')).toHaveText('Hello world');