Skip to content

Commit df77bb0

Browse files
Merge pull request #371 from abhishek-lambda/AT-281
At 281
2 parents b921c51 + 4d8bbc7 commit df77bb0

File tree

2 files changed

+109
-9
lines changed

2 files changed

+109
-9
lines changed

accessibility/plugin/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@ const Accessibility = (on, config) => {
6868
config.env.ACCESSIBILITY_REPORT_PATH = process.env.ACCESSIBILITY_REPORT_PATH;
6969
config.env.ACCESSIBILITY = process.env.ACCESSIBILITY;
7070
config.env.TEST_ID = process.env.TEST_ID;
71+
config.env.ACCESSIBILITY_OVERIDE_COMMANDS = process.env.ACCESSIBILITY_OVERIDE_COMMANDS;
7172
console.log(`parameter for accessibility report ACCESSIBILITY - ` + config.env.ACCESSIBILITY)
7273
console.log(`parameter for accessibility report WCAG_CRITERIA - ` + config.env.WCAG_CRITERIA)
7374
console.log(`parameter for accessibility report BEST_PRACTICE -` + config.env.BEST_PRACTICE)
7475
console.log(`parameter for accessibility report NEEDS_REVIEW -` + config.env.NEEDS_REVIEW)
7576
console.log(`parameter for accessibility report ACCESSIBILITY_REPORT_PATH -` + config.env.ACCESSIBILITY_REPORT_PATH)
7677
console.log(`parameter for accessibility report TEST_ID -` + config.env.TEST_ID)
7778
console.log(`parameter for accessibility report ACCESSIBILITY_EXTENSION_PATH -` + process.env.ACCESSIBILITY_EXTENSION_PATH)
79+
console.log(`parameter for accessibility report ACCESSIBILITY_OVERIDE_COMMANDS -` + config.env.ACCESSIBILITY_OVERIDE_COMMANDS)
7880

7981

8082
return config;

accessibility/scanner/index.js

Lines changed: 107 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const commandsToOverride = [
1010
'blur', 'focus', 'go', 'reload', 'submit', 'viewport', 'origin'
1111
];
1212

13+
const commandsToWrap = ['visit', 'click', 'type', 'request', 'dblclick', 'rightclick', 'clear', 'check', 'uncheck', 'select', 'trigger', 'selectFile', 'scrollIntoView', 'scroll', 'scrollTo', 'blur', 'focus', 'go', 'reload', 'submit', 'viewport', 'origin'];
14+
1315
let currentWindow = null;
1416
Cypress.Commands.add('storeWindowObject', () => {
1517
cy.window().then(win => {
@@ -148,20 +150,116 @@ async function processAccessibilityReport(url) {
148150
}
149151
}
150152

151-
commandsToOverride.forEach((command) => {
152-
Cypress.Commands.overwrite(command, (originalFn, url, options) => {
153+
function oldprocessAccessibilityReport(win){
154+
let wcagCriteriaValue = Cypress.env("WCAG_CRITERIA") || "wcag21a";
155+
let bestPracticeValue = Cypress.env("BEST_PRACTICE") || false;
156+
let needsReviewValue = Cypress.env("NEEDS_REVIEW") || true;
157+
bestPracticeValue = bestPracticeValue == "true" ? true : false;
158+
needsReviewValue = needsReviewValue == "true" ? true : false;
159+
const payloadToSend = {
160+
message: 'SET_CONFIG',
161+
wcagCriteria: wcagCriteriaValue,
162+
bestPractice: bestPracticeValue,
163+
needsReview: needsReviewValue
164+
}
165+
166+
console.log('log', "payload to send " + payloadToSend);
167+
let testId = Cypress.env("TEST_ID") || ""
168+
169+
const filePath = Cypress.env("ACCESSIBILITY_REPORT_PATH") || 'cypress/results/accessibilityReport_' + testId + '.json';
170+
171+
cy.wrap(setScanConfig(win, payloadToSend), {timeout: 30000}).then((res) => {
172+
console.log('logging config reponse', res);
173+
174+
const payload = {
175+
message: 'GET_LATEST_SCAN_DATA',
176+
}
177+
178+
cy.wrap(getScanData(win, payload), {timeout: 45000}).then((res) => {
179+
LambdatestLog('log', "scanning data ");
180+
181+
182+
cy.task('initializeFile', filePath).then((filePath) => {
183+
cy.task('readFileIfExists', filePath,{ log: true, timeout: 45000 }).then((result) => {
184+
let resultsArray = [{}];
185+
console.log('logging report', res);
186+
// If the file is not empty, parse the existing content
187+
if (result.exists && result.content) {
188+
try {
189+
resultsArray = JSON.parse(result.content);
190+
} catch (e) {
191+
console.log("parsing error for content " , result.content)
192+
console.log('Error parsing JSON file:', e);
193+
return;
194+
}
195+
} else if(!result.exists) {
196+
console.log('accessibility file does not exist');
197+
}
198+
if (res) {
199+
console.log('scanned data recieved is', res.message);
200+
}
201+
202+
if (res && res.message == "GET_LATEST_SCAN_DATA") {
203+
try {
204+
// Append the new result
205+
resultsArray.push(res);
206+
console.log('resultsarray logging', resultsArray);
207+
} catch (e) {
208+
console.log('Error pushing issues to array:', e);
209+
}
210+
}
211+
212+
// Write the updated content back to the file
213+
cy.writeFile(filePath, resultsArray, { log: true, timeout: 45000 });
214+
});
215+
});
216+
});
217+
218+
});
219+
}
220+
221+
const overRideCommands = Cypress.env("ACCESSIBILITY_OVERIDE_COMMANDS") || false;
222+
if (overRideCommands) {
223+
commandsToOverride.forEach((command) => {
224+
Cypress.Commands.overwrite(command, (originalFn, url, options) => {
225+
let isAccessibilityLoaded = Cypress.env("ACCESSIBILITY") || false;
226+
if (!isAccessibilityLoaded) {
227+
console.log('log', "Accessibility not enabled.");
228+
return originalFn(url, options);
229+
}
230+
231+
232+
return originalFn(url, options).then(async () => {
233+
234+
await processAccessibilityReport(url);
235+
})
236+
237+
});
238+
});
239+
}else{
240+
Cypress.on('command:start', async (command) => {
241+
if(!command || !command.attributes) return;
242+
if(command.attributes.name == 'window' || command.attributes.name == 'then' || command.attributes.name == 'wrap' || command.attributes.name == 'wait') {
243+
return;
244+
}
245+
246+
if (!commandsToWrap.includes(command.attributes.name)) return;
153247
let isAccessibilityLoaded = Cypress.env("ACCESSIBILITY") || false;
154-
if (!isAccessibilityLoaded) {
155-
console.log('log', "Accessibility not enabled.");
156-
return originalFn(url, options);
248+
if (!isAccessibilityLoaded){
249+
console.log('log', "accessibility not enabled " + isAccessibilityLoaded);
250+
return;
157251
}
158252

159253

160-
return originalFn(url, options).then(async () => {
161-
await processAccessibilityReport(url);
254+
console.log('log', "debugging scan form command " + command.attributes.name);
255+
256+
cy.window().then((win) => {
257+
oldprocessAccessibilityReport(win);
162258
})
259+
})
260+
261+
}
262+
163263

164-
});
165-
});
166264

167265

0 commit comments

Comments
 (0)