Skip to content

Commit

Permalink
SDK-1884: fixed scanner started twice.
Browse files Browse the repository at this point in the history
  • Loading branch information
osho-20 committed Dec 4, 2024
1 parent 02ea36a commit f03c489
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions bin/accessibility-automation/cypress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ new Promise(async (resolve, reject) => {
const isHttpOrHttps = /^(http|https):$/.test(win.location.protocol);
if (!isHttpOrHttps) {
resolve();
return;
}

function findAccessibilityAutomationElement() {
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -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;
});
}
})

Expand All @@ -75,6 +80,7 @@ new Promise((resolve) => {
const isHttpOrHttps = /^(http|https):$/.test(window.location.protocol);
if (!isHttpOrHttps) {
resolve();
return;
}

function findAccessibilityAutomationElement() {
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -120,7 +129,8 @@ new Promise((resolve) => {
.then(getSummary)
.catch((err) => {
resolve();
});
return;
});
}
})

Expand All @@ -129,6 +139,7 @@ new Promise((resolve) => {
const isHttpOrHttps = /^(http|https):$/.test(window.location.protocol);
if (!isHttpOrHttps) {
resolve();
return;
}

function findAccessibilityAutomationElement() {
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -174,7 +188,8 @@ new Promise((resolve) => {
.then(getResults)
.catch((err) => {
resolve();
});
return;
});
}
});

Expand All @@ -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() {
Expand All @@ -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;
}
Expand All @@ -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", {
Expand All @@ -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;
}

})
Expand Down Expand Up @@ -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}`);
}
})
});
Expand All @@ -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', () => {
Expand All @@ -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}`);
}

});

Expand All @@ -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}`);
}
});

0 comments on commit f03c489

Please sign in to comment.