chore: follow up to getTestById, escape it (#17650)

This commit is contained in:
Pavel Feldman 2022-09-28 08:23:47 -08:00 committed by GitHub
parent fbef53ba6c
commit 2a85806cc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 2 deletions

View file

@ -52,7 +52,7 @@ export class Locator implements api.Locator {
}
static getByTestIdSelector(testId: string): string {
return `css=[${Locator._testIdAttributeName}=${testId}]`;
return `css=[${Locator._testIdAttributeName}=${JSON.stringify(testId)}]`;
}
static getByTextSelector(text: string | RegExp, options?: { exact?: boolean }): string {

View file

@ -420,3 +420,8 @@ it('getByTestId should work', async ({ page }) => {
await expect(page.mainFrame().getByTestId('Hello')).toHaveText('Hello world');
await expect(page.get('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');
});

View file

@ -321,7 +321,7 @@ test('should support name', async ({ page }) => {
<div role="button" aria-label="Hallo"></div>
<div role="button" aria-label="Hello" aria-hidden="true"></div>
<div role="button" aria-label="123" aria-hidden="true"></div>
<div role="button" aria-label="foo\"bar" aria-hidden="true"></div>
<div role="button" aria-label='foo"bar' aria-hidden="true"></div>
`);
expect(await page.get(`role=button[name="Hello"]`).evaluateAll(els => els.map(e => e.outerHTML))).toEqual([
`<div role="button" aria-label="Hello"></div>`,