mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-03 07:51:12 +03:00
fix(locators): make regex escape work when multiple spaces are present (#17893)
This commit is contained in:
parent
dffa469718
commit
b64457d8ce
@ -68,7 +68,7 @@ export function escapeForTextSelector(text: string | RegExp, exact: boolean, cas
|
||||
if (exact)
|
||||
return '"' + text.replace(/["]/g, '\\"') + '"';
|
||||
if (text.includes('"') || text.includes('>>') || text[0] === '/')
|
||||
return `/${escapeForRegex(text).replace(/\s+/, '\\s+')}/` + (caseSensitive ? '' : 'i');
|
||||
return `/${escapeForRegex(text).replace(/\s+/g, '\\s+')}/` + (caseSensitive ? '' : 'i');
|
||||
return text;
|
||||
}
|
||||
|
||||
|
@ -108,29 +108,31 @@ it('getByTitle should work', async ({ page }) => {
|
||||
});
|
||||
|
||||
it('getBy escaping', async ({ page }) => {
|
||||
await page.setContent(`<label id=label for=control>Hello
|
||||
await page.setContent(`<label id=label for=control>Hello my
|
||||
wo"rld</label><input id=control />`);
|
||||
await page.$eval('input', input => {
|
||||
input.setAttribute('placeholder', 'hello\nwo"rld');
|
||||
input.setAttribute('title', 'hello\nwo"rld');
|
||||
input.setAttribute('alt', 'hello\nwo"rld');
|
||||
input.setAttribute('placeholder', 'hello my\nwo"rld');
|
||||
input.setAttribute('title', 'hello my\nwo"rld');
|
||||
input.setAttribute('alt', 'hello my\nwo"rld');
|
||||
});
|
||||
await expect(page.getByText('hello\nwo"rld')).toHaveAttribute('id', 'label');
|
||||
await expect(page.getByLabel('hello\nwo"rld')).toHaveAttribute('id', 'control');
|
||||
await expect(page.getByPlaceholder('hello\nwo"rld')).toHaveAttribute('id', 'control');
|
||||
await expect(page.getByAltText('hello\nwo"rld')).toHaveAttribute('id', 'control');
|
||||
await expect(page.getByTitle('hello\nwo"rld')).toHaveAttribute('id', 'control');
|
||||
await expect(page.getByText('hello my\nwo"rld')).toHaveAttribute('id', 'label');
|
||||
await expect(page.getByText('hello my wo"rld')).toHaveAttribute('id', 'label');
|
||||
await expect(page.getByLabel('hello my\nwo"rld')).toHaveAttribute('id', 'control');
|
||||
await expect(page.getByPlaceholder('hello my\nwo"rld')).toHaveAttribute('id', 'control');
|
||||
await expect(page.getByAltText('hello my\nwo"rld')).toHaveAttribute('id', 'control');
|
||||
await expect(page.getByTitle('hello my\nwo"rld')).toHaveAttribute('id', 'control');
|
||||
|
||||
await page.setContent(`<label id=label for=control>Hello
|
||||
await page.setContent(`<label id=label for=control>Hello my
|
||||
world</label><input id=control />`);
|
||||
await page.$eval('input', input => {
|
||||
input.setAttribute('placeholder', 'hello\nworld');
|
||||
input.setAttribute('title', 'hello\nworld');
|
||||
input.setAttribute('alt', 'hello\nworld');
|
||||
input.setAttribute('placeholder', 'hello my\nworld');
|
||||
input.setAttribute('title', 'hello my\nworld');
|
||||
input.setAttribute('alt', 'hello my\nworld');
|
||||
});
|
||||
await expect(page.getByText('hello\nworld')).toHaveAttribute('id', 'label');
|
||||
await expect(page.getByLabel('hello\nworld')).toHaveAttribute('id', 'control');
|
||||
await expect(page.getByPlaceholder('hello\nworld')).toHaveAttribute('id', 'control');
|
||||
await expect(page.getByAltText('hello\nworld')).toHaveAttribute('id', 'control');
|
||||
await expect(page.getByTitle('hello\nworld')).toHaveAttribute('id', 'control');
|
||||
await expect(page.getByText('hello my\nworld')).toHaveAttribute('id', 'label');
|
||||
await expect(page.getByText('hello my world')).toHaveAttribute('id', 'label');
|
||||
await expect(page.getByLabel('hello my\nworld')).toHaveAttribute('id', 'control');
|
||||
await expect(page.getByPlaceholder('hello my\nworld')).toHaveAttribute('id', 'control');
|
||||
await expect(page.getByAltText('hello my\nworld')).toHaveAttribute('id', 'control');
|
||||
await expect(page.getByTitle('hello my\nworld')).toHaveAttribute('id', 'control');
|
||||
});
|
||||
|
@ -740,11 +740,11 @@ test('test.setTimeout should work separately in afterAll', async ({ runInlineTes
|
||||
});
|
||||
test.afterAll(async () => {
|
||||
console.log('\\n%%afterAll');
|
||||
test.setTimeout(1000);
|
||||
await new Promise(f => setTimeout(f, 800));
|
||||
test.setTimeout(3000);
|
||||
await new Promise(f => setTimeout(f, 2000));
|
||||
});
|
||||
`,
|
||||
}, { timeout: '100' });
|
||||
}, { timeout: '1000' });
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.passed).toBe(1);
|
||||
expect(result.output.split('\n').filter(line => line.startsWith('%%'))).toEqual([
|
||||
|
Loading…
Reference in New Issue
Block a user