feat(text selector): normalize spaces in lax mode (#4312)

This commit is contained in:
Dmitry Gozman 2020-11-03 04:37:06 -08:00 committed by GitHub
parent 8fed0b3319
commit 924cc9894a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -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.

View File

@ -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&nbsp;in</span><span>Hello\n \nworld</span>`);
expect(await page.$eval(`text=Sign in`, e => e.outerHTML)).toBe('<span>Sign&nbsp;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}) => {