From ee64090001fe56adc4d911c789beda3c22f09f38 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 30 May 2022 11:29:04 +0200 Subject: [PATCH] MOBILE-4031 behat: Fix search text with double quotes --- src/testing/services/behat-dom.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/testing/services/behat-dom.ts b/src/testing/services/behat-dom.ts index 101cb9657..7a0e79083 100644 --- a/src/testing/services/behat-dom.ts +++ b/src/testing/services/behat-dom.ts @@ -89,7 +89,10 @@ export class TestingBehatDomUtilsService { text: string, options: TestingBehatFindOptions, ): ElementsWithExact[] { - const attributesSelector = `[aria-label*="${text}"], a[title*="${text}"], img[alt*="${text}"], [placeholder*="${text}"]`; + // Escape double quotes to prevent breaking the query selector. + const escapedText = text.replace(/"/g, '\\"'); + const attributesSelector = `[aria-label*="${escapedText}"], a[title*="${escapedText}"], ` + + `img[alt*="${escapedText}"], [placeholder*="${escapedText}"]`; const elements = Array.from(container.querySelectorAll(attributesSelector)) .filter((element => this.isElementVisible(element, container)))