Skip to content

Commit 7d0d8cf

Browse files
ensure backward compatability
1 parent 1a99496 commit 7d0d8cf

File tree

2 files changed

+107
-9
lines changed

2 files changed

+107
-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: 105 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,116 @@ async function processAccessibilityReport(url) {
148148
}
149149
}
150150

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

159251

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

164-
});
165-
});
166262

167263

0 commit comments

Comments
 (0)