From d216f167ff3d6183331b60e4f9cabe00343a9d9a Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Mon, 17 Jun 2024 13:00:41 -0700 Subject: [PATCH] fix(codegen): trim alt selectors to 80 chars Fixes https://github.com/microsoft/playwright/issues/31254 --- .../src/server/injected/selectorGenerator.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/playwright-core/src/server/injected/selectorGenerator.ts b/packages/playwright-core/src/server/injected/selectorGenerator.ts index 7e4f51b1b2..e67d842f29 100644 --- a/packages/playwright-core/src/server/injected/selectorGenerator.ts +++ b/packages/playwright-core/src/server/injected/selectorGenerator.ts @@ -528,7 +528,7 @@ function suitableTextAlternatives(text: string) { const match = text.match(/^([\d.,]+)[^.,\w]/); const leadingNumberLength = match ? match[1].length : 0; if (leadingNumberLength) { - const alt = text.substring(leadingNumberLength).trimStart(); + const alt = trimWordBoundary(text.substring(leadingNumberLength).trimStart(), 80); result.push({ text: alt, scoreBouns: alt.length <= 30 ? 2 : 1 }); } } @@ -537,7 +537,7 @@ function suitableTextAlternatives(text: string) { const match = text.match(/[^.,\w]([\d.,]+)$/); const trailingNumberLength = match ? match[1].length : 0; if (trailingNumberLength) { - const alt = text.substring(0, text.length - trailingNumberLength).trimEnd(); + const alt = trimWordBoundary(text.substring(0, text.length - trailingNumberLength).trimEnd(), 80); result.push({ text: alt, scoreBouns: alt.length <= 30 ? 2 : 1 }); } } @@ -551,7 +551,7 @@ function suitableTextAlternatives(text: string) { result = result.filter(r => r.text); if (!result.length) - result.push({ text: text.substring(0, 80), scoreBouns: 0 }); + result.push({ text: trimWordBoundary(text, 80), scoreBouns: 0 }); return result; }