Skip to content

Commit 042a474

Browse files
fix overwrite command
1 parent 6db7f95 commit 042a474

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

accessibility/scanner/index.js

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const LambdatestLog = (message) => {
33
if (!Cypress.env('LAMBDATEST_LOGS')) return;
44
cy.task('lambdatest_log', message);
5-
}
5+
}
66

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

@@ -133,30 +133,31 @@ function processAccessibilityReport(win){
133133
});
134134
}
135135

136-
// Cypress.on('window:load', async (command) => {
137-
// if(!command || !command.attributes) return;
138-
// if(command.attributes.name == 'window' || command.attributes.name == 'then' || command.attributes.name == 'wrap' || command.attributes.name == 'wait') {
139-
// return;
140-
// }
141-
//
142-
// if (!commandsToWrap.includes(command.attributes.name)) return;
143-
// let isAccessibilityLoaded = Cypress.env("ACCESSIBILITY") || false;
144-
// if (!isAccessibilityLoaded){
145-
// console.log('log', "accessibility not enabled " + isAccessibilityLoaded);
146-
// return;
147-
// }
148-
//
149-
//
150-
// console.log('log', "debugging scan form command " + command.attributes.name);
151-
//
152-
// cy.window().then((win) => {
153-
// processAccessibilityReport(win);
154-
// });
155-
// })
136+
Cypress.on('command:start', async (command) => {
137+
if(!command || !command.attributes) return;
138+
if(command.attributes.name == 'window' || command.attributes.name == 'then' || command.attributes.name == 'wrap' || command.attributes.name == 'wait') {
139+
return;
140+
}
141+
142+
if (!commandsToWrap.includes(command.attributes.name)) return;
143+
let isAccessibilityLoaded = Cypress.env("ACCESSIBILITY") || false;
144+
if (!isAccessibilityLoaded){
145+
console.log('log', "accessibility not enabled " + isAccessibilityLoaded);
146+
return;
147+
}
148+
149+
150+
console.log('log', "debugging scan form command " + command.attributes.name);
151+
152+
cy.window().then((win) => {
153+
processAccessibilityReport(win);
154+
});
155+
})
156156

157157
// Ensure scan runs AFTER visit completes
158158
Cypress.Commands.overwrite('visit', (originalFn, url, options) => {
159-
return originalFn(url, options).then(() => {
159+
function getReportAfterVisiting() {
160+
originalFn(url, options)
160161
let isAccessibilityLoaded = Cypress.env("ACCESSIBILITY") || false;
161162
if (!isAccessibilityLoaded) {
162163
console.log('log', "Accessibility not enabled.");
@@ -167,7 +168,9 @@ Cypress.Commands.overwrite('visit', (originalFn, url, options) => {
167168
console.log('log', "Running accessibility scan after visit: " + url);
168169
processAccessibilityReport(win);
169170
});
170-
});
171+
}
172+
173+
return getReportAfterVisiting();
171174
});
172175

173176

@@ -178,15 +181,15 @@ return;
178181

179182

180183
afterEach(() => {
181-
console.log("after each hook")
182-
let isAccessibilityLoaded = Cypress.env("ACCESSIBILITY") || false;
183-
if (!isAccessibilityLoaded){
184-
console.log('log', "accessibility not enabled " + isAccessibilityLoaded);
185-
return;
186-
}
187-
cy.window().then((win) => {
188-
processAccessibilityReport(win);
189-
})
184+
console.log("after each hook")
185+
let isAccessibilityLoaded = Cypress.env("ACCESSIBILITY") || false;
186+
if (!isAccessibilityLoaded){
187+
console.log('log', "accessibility not enabled " + isAccessibilityLoaded);
188+
return;
189+
}
190+
cy.window().then((win) => {
191+
processAccessibilityReport(win);
192+
})
190193

191194

192195
})

0 commit comments

Comments
 (0)