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;
|
this.selector = selector;
|
||||||
if (options?.hasText) {
|
if (options?.hasText) {
|
||||||
const text = options.hasText;
|
const text = options.hasText;
|
||||||
const matcher = text instanceof RegExp ? 'text-matches' : 'has-text';
|
if (text instanceof RegExp)
|
||||||
const source = escapeWithQuotes(text instanceof RegExp ? text.source : text, '"');
|
this.selector += ` >> :scope:text-matches(${escapeWithQuotes(text.source, '"')}, "${text.flags}")`;
|
||||||
this.selector += ` >> :scope:${matcher}(${source})`;
|
else
|
||||||
|
this.selector += ` >> :scope:has-text(${escapeWithQuotes(text)})`;
|
||||||
}
|
}
|
||||||
const parsed = injectedScript.parseSelector(this.selector);
|
const parsed = injectedScript.parseSelector(this.selector);
|
||||||
this.element = injectedScript.querySelector(parsed, document, false);
|
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 }) => {
|
it('should support playwright.locator.values', async ({ page }) => {
|
||||||
await page.setContent('<div>Hello<div>Bar</div></div>');
|
await page.setContent('<div>Hello<div>Bar</div></div>');
|
||||||
const length = await page.evaluate(`playwright.locator('div', { hasText: 'Hello' }).elements.length`);
|
expect(await page.evaluate(`playwright.locator('div', { hasText: 'Hello' }).elements.length`)).toBe(1);
|
||||||
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: /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