Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(text selector): normalize spaces in lax mode (#4312)
Dmitry Gozman924cc9894a89
diff --git a/src/server/injected/textSelectorEngine.ts b/src/server/injected/textSelectorEngine.tsindex 5f4c85c480..aa2a3243a1 100644--- a/src/server/injected/textSelectorEngine.ts+++ b/src/server/injected/textSelectorEngine.ts@@ -76,8 +76,8 @@ function createMatcher(selector: string): Matcher {const re = new RegExp(selector.substring(1, lastSlash), selector.substring(lastSlash + 1));return text => re.test(text);}- selector = selector.trim().toLowerCase();- return text => text.toLowerCase().includes(selector);+ selector = selector.trim().toLowerCase().replace(/\s+/g, ' ');+ return text => text.toLowerCase().replace(/\s+/g, ' ').includes(selector);}// Skips <head>, <script> and <style> elements and all their children.diff --git a/test/selectors-text.spec.ts b/test/selectors-text.spec.tsindex 874b7ef2c3..e6f85841fa 100644--- a/test/selectors-text.spec.ts+++ b/test/selectors-text.spec.ts@@ -94,6 +94,16 @@ it('query', async ({page, isWebKit}) => {});expect(await page.$eval(`text=lowo`, e => e.outerHTML)).toBe('<div>helloworld</div>');expect(await page.$$eval(`text=lowo`, els => els.map(e => e.outerHTML).join(''))).toBe('<div>helloworld</div><span>helloworld</span>');++ await page.setContent(`<span>Sign in</span><span>Hello\n \nworld</span>`);+ expect(await page.$eval(`text=Sign in`, e => e.outerHTML)).toBe('<span>Sign in</span>');+ expect((await page.$$(`text=Sign \tin`)).length).toBe(1);+ expect(await page.$(`text="Sign in"`)).toBe(null);+ expect((await page.$$(`text="Sign in"`)).length).toBe(0);+ expect(await page.$eval(`text=lo wo`, e => e.outerHTML)).toBe('<span>Hello\n \nworld</span>');+ expect(await page.$(`text="lo wo"`)).toBe(null);+ expect((await page.$$(`text=lo \nwo`)).length).toBe(1);+ expect((await page.$$(`text="lo wo"`)).length).toBe(0);});it('create', async ({page}) => {