Skip to content

Commit 46965e1

Browse files
Merge pull request #379 from LambdaTest/AT-281
At 281
2 parents 320c8a3 + c356dc8 commit 46965e1

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

accessibility/scanner/index.js

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@ const commandsToOverride = [
1212

1313
const commandsToWrap = ['visit', 'click', 'type', 'request', 'dblclick', 'rightclick', 'clear', 'check', 'uncheck', 'select', 'trigger', 'selectFile', 'scrollIntoView', 'scroll', 'scrollTo', 'blur', 'focus', 'go', 'reload', 'submit', 'viewport', 'origin'];
1414

15-
let currentWindow = null;
16-
Cypress.Commands.add('storeWindowObject', () => {
17-
cy.window().then(win => {
18-
currentWindow = win;
19-
});
20-
});
21-
22-
beforeEach(() => {
23-
cy.storeWindowObject();
24-
});
2515

2616
const setScanConfig = (win, payload) => {
2717
return new Promise((resolve, reject) => {
@@ -86,7 +76,7 @@ const sendScanData = (win, payload) => {
8676
});
8777
};
8878

89-
async function processAccessibilityReport(url) {
79+
async function processAccessibilityReport(url,windowNew) {
9080
try {
9181
let wcagCriteriaValue = Cypress.env("WCAG_CRITERIA") || "wcag21a";
9282
let bestPracticeValue = Cypress.env("BEST_PRACTICE") === "true";
@@ -101,7 +91,7 @@ async function processAccessibilityReport(url) {
10191

10292
console.log('log', "SET SCAN: Payload to send: for url: ", payloadToSend,url);
10393
try {
104-
let setResult = await setScanConfig(currentWindow, payloadToSend);
94+
let setResult = await setScanConfig(windowNew, payloadToSend);
10595
console.log('SET SCAN: response:', setResult);
10696
} catch (err) {
10797
console.error("SET SCAN: Error while setting scan", err);
@@ -111,7 +101,7 @@ async function processAccessibilityReport(url) {
111101
let scanData;
112102
try {
113103
const payload = {message: 'GET_LATEST_SCAN_DATA'};
114-
scanData = await getScanData(currentWindow, payload);
104+
scanData = await getScanData(windowNew, payload);
115105
LambdatestLog("GET SCAN:LambdaTest Accessibility: Scanning URL");
116106
} catch (err) {
117107
console.error("GET SCAN:Error while setting scan", err);
@@ -134,7 +124,7 @@ async function processAccessibilityReport(url) {
134124
apiUrl: reportAPI
135125
};
136126
try{
137-
let response = await sendScanData(currentWindow,payloadToSend);
127+
let response = await sendScanData(windowNew,payloadToSend);
138128
console.log("Accessibility Report Response:", response);
139129
}catch(e){
140130
console.error("Error in Accessibility Report Response:",e);
@@ -227,12 +217,16 @@ if (overRideCommands) {
227217
console.log('log', "Accessibility not enabled.");
228218
return originalFn(url, options);
229219
}
230-
231-
232-
return originalFn(url, options).then(async () => {
233-
234-
await processAccessibilityReport(url);
235-
})
220+
Cypress.log({
221+
name: command, // Display the passed command name
222+
displayName: `${command}`, // Change how it looks in the Cypress log
223+
message: url,
224+
});
225+
return cy.window().then((currentWindowNew) => {
226+
return originalFn(url, options).then(() => {
227+
return processAccessibilityReport(url, currentWindowNew);
228+
});
229+
});
236230

237231
});
238232
});

0 commit comments

Comments
 (0)