Skip to content

Commit 02ea36a

Browse files
committed
SDK-1884: added error debugging logs.
1 parent 234fcfd commit 02ea36a

File tree

1 file changed

+22
-17
lines changed
  • bin/accessibility-automation/cypress

1 file changed

+22
-17
lines changed

bin/accessibility-automation/cypress/index.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ const browserStackLog = (message) => {
66
}
77

88
const commandsToWrap = ['visit', 'click', 'type', 'request', 'dblclick', 'rightclick', 'clear', 'check', 'uncheck', 'select', 'trigger', 'selectFile', 'scrollIntoView', 'scroll', 'scrollTo', 'blur', 'focus', 'go', 'reload', 'submit', 'viewport', 'origin'];
9+
const commandToOverwrite = ['visit', 'click', 'type', 'request', 'dblclick', 'rightclick', 'clear', 'check', 'uncheck', 'select', 'trigger', 'selectFile', 'scrollIntoView', 'scrollTo', 'blur', 'focus', 'go', 'reload', 'submit', 'viewport', 'origin'];
10+
commandToOverwrite.forEach((command) => {
11+
Cypress.Commands.overwrite(command, (originalFn, url, options) => {
12+
const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest || Cypress.mocha.getRunner().suite.ctx._runnable;
13+
let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes);
14+
if (!shouldScanTestForAccessibility) return;
15+
cy.wrap(null).performScan().then(() => originalFn(url, options));
16+
});
17+
});
918

1019
const performScan = (win, payloadToSend) =>
1120
new Promise(async (resolve, reject) => {
@@ -222,7 +231,8 @@ new Promise( (resolve, reject) => {
222231
resolve("Scanner is not ready on the page after multiple retries. after run");
223232
});
224233
}
225-
} catch(er) {
234+
} catch(error) {
235+
browserStackLog(`Error in saving results with error: ${error.message}`);
226236
resolve()
227237
}
228238

@@ -254,24 +264,13 @@ const shouldScanForAccessibility = (attributes) => {
254264
const included = includeTagArray.length === 0 || includeTags.some((include) => fullTestName.includes(include));
255265
shouldScanTestForAccessibility = !excluded && included;
256266
} catch (error) {
257-
browserStackLog("Error while validating test case for accessibility before scanning. Error : ", error);
267+
browserStackLog(`Error while validating test case for accessibility before scanning. Error : ${error.message}`);
258268
}
259269
}
260270

261271
return shouldScanTestForAccessibility;
262272
}
263273

264-
const commandToOverwrite = [ 'visit', 'click', 'type', 'request', 'dblclick', 'rightclick', 'clear', 'check', 'uncheck', 'select', 'trigger', 'selectFile', 'scrollIntoView', 'scrollTo', 'blur', 'focus', 'go', 'reload', 'submit', 'viewport', 'origin'];
265-
commandToOverwrite.forEach((command) => {
266-
Cypress.Commands.overwrite(command, (originalFn, url, options) => {
267-
const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest || Cypress.mocha.getRunner().suite.ctx._runnable;
268-
let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes);
269-
if (!shouldScanTestForAccessibility) return;
270-
cy.wrap(null).performScan().then(() => originalFn(url, options));
271-
});
272-
});
273-
274-
275274
afterEach(() => {
276275
const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest;
277276
cy.window().then(async (win) => {
@@ -314,6 +313,7 @@ afterEach(() => {
314313
})
315314

316315
} catch (er) {
316+
browserStackLog(`Error in saving results with error: ${er.message}`);
317317
}
318318
})
319319
});
@@ -331,7 +331,9 @@ Cypress.Commands.add('performScan', () => {
331331
browserStackLog(`Performing accessibility scan`);
332332
cy.wrap(performScan(win), {timeout:40000});
333333
});
334-
} catch {}
334+
} catch(error) {
335+
browserStackLog(`Error in performing scan with error: ${error.message}`);
336+
}
335337
})
336338

337339
Cypress.Commands.add('getAccessibilityResultsSummary', () => {
@@ -347,7 +349,9 @@ Cypress.Commands.add('getAccessibilityResultsSummary', () => {
347349
browserStackLog('Getting accessibility results summary');
348350
return await getAccessibilityResultsSummary(win);
349351
});
350-
} catch {}
352+
} catch(error) {
353+
browserStackLog(`Error in getting accessibilty results summary with error: ${error.message}`);
354+
}
351355

352356
});
353357

@@ -368,6 +372,7 @@ Cypress.Commands.add('getAccessibilityResults', () => {
368372
return await getAccessibilityResults(win);
369373
});
370374

371-
} catch {}
372-
375+
} catch(error) {
376+
browserStackLog(`Error in getting accessibilty results with error: ${error.message}`);
377+
}
373378
});

0 commit comments

Comments
 (0)