From f03c4899a9c5e4521dccc2fa4072864799ddbc27 Mon Sep 17 00:00:00 2001 From: YASH JAIN Date: Wed, 4 Dec 2024 16:26:03 +0530 Subject: [PATCH] SDK-1884: fixed scanner started twice. --- bin/accessibility-automation/cypress/index.js | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 532476b1..d91bd07e 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -21,6 +21,7 @@ new Promise(async (resolve, reject) => { const isHttpOrHttps = /^(http|https):$/.test(win.location.protocol); if (!isHttpOrHttps) { resolve(); + return; } function findAccessibilityAutomationElement() { @@ -38,9 +39,11 @@ new Promise(async (resolve, reject) => { "Accessibility Automation Scanner is not ready on the page." ) ); + return; } else if (findAccessibilityAutomationElement()) { clearInterval(intervalID); resolve("Scanner set"); + return; } else { count += 1; } @@ -52,6 +55,7 @@ new Promise(async (resolve, reject) => { function onScanComplete() { win.removeEventListener("A11Y_SCAN_FINISHED", onScanComplete); resolve(); + return; } win.addEventListener("A11Y_SCAN_FINISHED", onScanComplete); @@ -66,7 +70,8 @@ new Promise(async (resolve, reject) => { .then(startScan) .catch(async (err) => { resolve("Scanner is not ready on the page after multiple retries. performscan"); - }); + return; + }); } }) @@ -75,6 +80,7 @@ new Promise((resolve) => { const isHttpOrHttps = /^(http|https):$/.test(window.location.protocol); if (!isHttpOrHttps) { resolve(); + return; } function findAccessibilityAutomationElement() { @@ -92,9 +98,11 @@ new Promise((resolve) => { "Accessibility Automation Scanner is not ready on the page." ) ); + return; } else if (findAccessibilityAutomationElement()) { clearInterval(intervalID); resolve("Scanner set"); + return; } else { count += 1; } @@ -106,6 +114,7 @@ new Promise((resolve) => { function onReceiveSummary(event) { win.removeEventListener("A11Y_RESULTS_SUMMARY", onReceiveSummary); resolve(event.detail); + return; } win.addEventListener("A11Y_RESULTS_SUMMARY", onReceiveSummary); @@ -120,7 +129,8 @@ new Promise((resolve) => { .then(getSummary) .catch((err) => { resolve(); - }); + return; + }); } }) @@ -129,6 +139,7 @@ new Promise((resolve) => { const isHttpOrHttps = /^(http|https):$/.test(window.location.protocol); if (!isHttpOrHttps) { resolve(); + return; } function findAccessibilityAutomationElement() { @@ -146,9 +157,11 @@ new Promise((resolve) => { "Accessibility Automation Scanner is not ready on the page." ) ); + return; } else if (findAccessibilityAutomationElement()) { clearInterval(intervalID); resolve("Scanner set"); + return; } else { count += 1; } @@ -160,6 +173,7 @@ new Promise((resolve) => { function onReceivedResult(event) { win.removeEventListener("A11Y_RESULTS_RESPONSE", onReceivedResult); resolve(event.detail); + return; } win.addEventListener("A11Y_RESULTS_RESPONSE", onReceivedResult); @@ -174,7 +188,8 @@ new Promise((resolve) => { .then(getResults) .catch((err) => { resolve(); - }); + return; + }); } }); @@ -184,6 +199,7 @@ new Promise( (resolve, reject) => { const isHttpOrHttps = /^(http|https):$/.test(win.location.protocol); if (!isHttpOrHttps) { resolve("Unable to save accessibility results, Invalid URL."); + return; } function findAccessibilityAutomationElement() { @@ -201,9 +217,11 @@ new Promise( (resolve, reject) => { "Accessibility Automation Scanner is not ready on the page." ) ); + return; } else if (findAccessibilityAutomationElement()) { clearInterval(intervalID); resolve("Scanner set"); + return; } else { count += 1; } @@ -214,6 +232,7 @@ new Promise( (resolve, reject) => { function saveResults() { function onResultsSaved(event) { resolve(); + return; } win.addEventListener("A11Y_RESULTS_SAVED", onResultsSaved); const e = new CustomEvent("A11Y_SAVE_RESULTS", { @@ -229,11 +248,13 @@ new Promise( (resolve, reject) => { .then(saveResults) .catch(async (err) => { resolve("Scanner is not ready on the page after multiple retries. after run"); + return; }); } } catch(error) { - browserStackLog(`Error in saving results with error: ${error.message}`); - resolve() + browserStackLog(`Error in saving results with error: ${error.message}`); + resolve(); + return; } }) @@ -313,7 +334,7 @@ afterEach(() => { }) } catch (er) { - browserStackLog(`Error in saving results with error: ${er.message}`); + browserStackLog(`Error in saving results with error: ${er.message}`); } }) }); @@ -332,8 +353,8 @@ Cypress.Commands.add('performScan', () => { cy.wrap(performScan(win), {timeout:40000}); }); } catch(error) { - browserStackLog(`Error in performing scan with error: ${error.message}`); - } + browserStackLog(`Error in performing scan with error: ${error.message}`); + } }) Cypress.Commands.add('getAccessibilityResultsSummary', () => { @@ -350,8 +371,8 @@ Cypress.Commands.add('getAccessibilityResultsSummary', () => { return await getAccessibilityResultsSummary(win); }); } catch(error) { - browserStackLog(`Error in getting accessibilty results summary with error: ${error.message}`); - } + browserStackLog(`Error in getting accessibilty results summary with error: ${error.message}`); + } }); @@ -373,6 +394,6 @@ Cypress.Commands.add('getAccessibilityResults', () => { }); } catch(error) { - browserStackLog(`Error in getting accessibilty results with error: ${error.message}`); - } + browserStackLog(`Error in getting accessibilty results with error: ${error.message}`); + } });