fix(selectors): max hasText regex against nested nodes (#15638)
This commit is contained in:
parent
edd8f44066
commit
cb81d23ad6
|
|
@ -42,7 +42,7 @@ export class Locator implements api.Locator {
|
|||
if (options?.hasText) {
|
||||
const text = options.hasText;
|
||||
if (isRegExp(text))
|
||||
this._selector += ` >> :scope:text-matches(${escapeWithQuotes(text.source, '"')}, "${text.flags}")`;
|
||||
this._selector += ` >> has=${JSON.stringify('text=' + text.toString())}`;
|
||||
else
|
||||
this._selector += ` >> :scope:has-text(${escapeWithQuotes(text, '"')})`;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,11 +92,22 @@ it('should filter by regex and regexp flags', async ({ page }) => {
|
|||
|
||||
it('should filter by case-insensitive regex in a child', async ({ page }) => {
|
||||
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/15348' });
|
||||
it.fixme();
|
||||
await page.setContent(`<div class="test"><h5>Title Text</h5></div>`);
|
||||
await expect(page.locator('div', { hasText: /^title text$/i })).toHaveText('Title Text');
|
||||
});
|
||||
|
||||
it('should filter by case-insensitive regex in multiple children', async ({ page }) => {
|
||||
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/15348' });
|
||||
await page.setContent(`<div class="test"><h5>Title</h5> <h2><i>Text</i></h2></div>`);
|
||||
await expect(page.locator('div', { hasText: /^title text$/i })).toHaveClass('test');
|
||||
});
|
||||
|
||||
it('should filter by regex with special symbols', async ({ page }) => {
|
||||
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/15348' });
|
||||
await page.setContent(`<div class="test"><h5>First/"and"</h5><h2><i>Second\\</i></h2></div>`);
|
||||
await expect(page.locator('div', { hasText: /^first\/".*"second\\$/si })).toHaveClass('test');
|
||||
});
|
||||
|
||||
it('should support has:locator', async ({ page, trace }) => {
|
||||
it.skip(trace === 'on');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue