fix: playwright.locator.hasText RegExp flag serialisation in Console API (#11516)
This commit is contained in:
parent
33c82a42c0
commit
fb139cefac
|
|
@ -28,9 +28,10 @@ function createLocator(injectedScript: InjectedScript, initial: string, options?
|
|||
this.selector = selector;
|
||||
if (options?.hasText) {
|
||||
const text = options.hasText;
|
||||
const matcher = text instanceof RegExp ? 'text-matches' : 'has-text';
|
||||
const source = escapeWithQuotes(text instanceof RegExp ? text.source : text, '"');
|
||||
this.selector += ` >> :scope:${matcher}(${source})`;
|
||||
if (text instanceof RegExp)
|
||||
this.selector += ` >> :scope:text-matches(${escapeWithQuotes(text.source, '"')}, "${text.flags}")`;
|
||||
else
|
||||
this.selector += ` >> :scope:has-text(${escapeWithQuotes(text)})`;
|
||||
}
|
||||
const parsed = injectedScript.parseSelector(this.selector);
|
||||
this.element = injectedScript.querySelector(parsed, document, false);
|
||||
|
|
|
|||
|
|
@ -54,6 +54,9 @@ it('should support playwright.locator.value', async ({ page }) => {
|
|||
|
||||
it('should support playwright.locator.values', async ({ page }) => {
|
||||
await page.setContent('<div>Hello<div>Bar</div></div>');
|
||||
const length = await page.evaluate(`playwright.locator('div', { hasText: 'Hello' }).elements.length`);
|
||||
expect(length).toBe(1);
|
||||
expect(await page.evaluate(`playwright.locator('div', { hasText: 'Hello' }).elements.length`)).toBe(1);
|
||||
expect(await page.evaluate(`playwright.locator('div', { hasText: 'HElLo' }).elements.length`)).toBe(1);
|
||||
expect(await page.evaluate(`playwright.locator('div', { hasText: /ELL/ }).elements.length`)).toBe(0);
|
||||
expect(await page.evaluate(`playwright.locator('div', { hasText: /ELL/i }).elements.length`)).toBe(1);
|
||||
expect(await page.evaluate(`playwright.locator('div', { hasText: /Hello/ }).elements.length`)).toBe(1);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue