From 5443b66636d697dc8ed0f6ee12497936b2e1f5e1 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Mon, 17 Jun 2024 16:32:22 -0700 Subject: [PATCH] fix(codegen): trim alt selectors to 80 chars (#31346) Fixes https://github.com/microsoft/playwright/issues/31254 --- .../playwright-core/src/server/injected/selectorGenerator.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/playwright-core/src/server/injected/selectorGenerator.ts b/packages/playwright-core/src/server/injected/selectorGenerator.ts index 7e4f51b1b2..eaa330a0e5 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 }); } }