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) {
|
if (options?.hasText) {
|
||||||
const text = options.hasText;
|
const text = options.hasText;
|
||||||
if (isRegExp(text))
|
if (isRegExp(text))
|
||||||
this._selector += ` >> :scope:text-matches(${escapeWithQuotes(text.source, '"')}, "${text.flags}")`;
|
this._selector += ` >> has=${JSON.stringify('text=' + text.toString())}`;
|
||||||
else
|
else
|
||||||
this._selector += ` >> :scope:has-text(${escapeWithQuotes(text, '"')})`;
|
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('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.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 page.setContent(`<div class="test"><h5>Title Text</h5></div>`);
|
||||||
await expect(page.locator('div', { hasText: /^title text$/i })).toHaveText('Title Text');
|
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('should support has:locator', async ({ page, trace }) => {
|
||||||
it.skip(trace === 'on');
|
it.skip(trace === 'on');
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue