Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(selectors): don't drop the engine name when a non-xpath source starts with ".." (#41475)

Devin Roussofd9b11f2db30
diff --git a/packages/isomorphic/selectorParser.ts b/packages/isomorphic/selectorParser.ts
index c5c322cb7a..9da6c48cd0 100644
--- a/packages/isomorphic/selectorParser.ts
+++ b/packages/isomorphic/selectorParser.ts
@@ -132,7 +132,7 @@ export function stringifySelector(selector: string | ParsedSelector, forceEngine
if (!forceEngineName && i !== selector.capture) {
if (p.name === 'css')
includeEngine = false;
- else if (p.name === 'xpath' && p.source.startsWith('//') || p.source.startsWith('..'))
+ else if (p.name === 'xpath' && (p.source.startsWith('//') || p.source.startsWith('..')))
includeEngine = false;
}
const prefix = includeEngine ? p.name + '=' : '';
diff --git a/tests/page/page-strict.spec.ts b/tests/page/page-strict.spec.ts
index e85697d6d6..afbc317116 100644
--- a/tests/page/page-strict.spec.ts
+++ b/tests/page/page-strict.spec.ts
@@ -119,3 +119,10 @@ it('should escape tag names', async ({ page }) => {
expect(error.message).toContain(`getByText('special test description').first()`);
expect(error.message).toContain(`locator('q\\\\:template').filter({ hasText: 'special test description' })`);
});
+
+it('should keep the engine name for a "text=.." selector in strict mode', async ({ page }) => {
+ await page.setContent(`<div>..loading</div><div>..loading</div>`);
+ const error = await page.locator('text=..loading').hover().catch(e => e);
+ expect(error.message).toContain('strict mode violation');
+ expect(error.message).toContain(`locator('text=..loading')`);
+});