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 da5fc16
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions bin/accessibility-automation/cypress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ commandToOverwrite.forEach((command) => {
Cypress.Commands.overwrite(command, (originalFn, url, options) => {
const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest || Cypress.mocha.getRunner().suite.ctx._runnable;
let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes);
if (!shouldScanTestForAccessibility) return;
cy.wrap(null).performScan().then(() => originalFn(url, options));
if (!shouldScanTestForAccessibility) {
cy.wrap(null).then(() => originalFn(url, options));
return;
}
else cy.wrap(null).performScan().then(() => originalFn(url, options));
});
});

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

function findAccessibilityAutomationElement() {
Expand All @@ -38,9 +42,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 +58,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 +73,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 +83,7 @@ new Promise((resolve) => {
const isHttpOrHttps = /^(http|https):$/.test(window.location.protocol);
if (!isHttpOrHttps) {
resolve();
return;
}

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

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

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

Expand All @@ -184,6 +202,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 +220,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 +235,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 +251,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 +337,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 +356,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 +374,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 +397,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 da5fc16

Please sign in to comment.