-
Notifications
You must be signed in to change notification settings - Fork 39
SDK-1884: Cypress SDK not wrapping A11Y commands appropriately #949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
234fcfd
02ea36a
da5fc16
e8d4bc9
ccde61e
f96066a
f04069d
deefe01
2148ba1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,15 @@ const browserStackLog = (message) => { | |
} | ||
|
||
const commandsToWrap = ['visit', 'click', 'type', 'request', 'dblclick', 'rightclick', 'clear', 'check', 'uncheck', 'select', 'trigger', 'selectFile', 'scrollIntoView', 'scroll', 'scrollTo', 'blur', 'focus', 'go', 'reload', 'submit', 'viewport', 'origin']; | ||
const commandToOverwrite = ['visit', 'click', 'type', 'request', 'dblclick', 'rightclick', 'clear', 'check', 'uncheck', 'select', 'trigger', 'selectFile', 'scrollIntoView', 'scrollTo', 'blur', 'focus', 'go', 'reload', 'submit', 'viewport', 'origin']; | ||
commandToOverwrite.forEach((command) => { | ||
Cypress.Commands.overwrite(command, (originalFn, url, options) => { | ||
const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest || Cypress.mocha.getRunner().suite.ctx._runnable; | ||
let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); | ||
if (!shouldScanTestForAccessibility) return; | ||
cy.wrap(null).performScan().then(() => originalFn(url, options)); | ||
}); | ||
}); | ||
|
||
const performScan = (win, payloadToSend) => | ||
new Promise(async (resolve, reject) => { | ||
|
@@ -18,7 +27,7 @@ new Promise(async (resolve, reject) => { | |
return win.document.querySelector("#accessibility-automation-element"); | ||
} | ||
|
||
function waitForScannerReadiness(retryCount = 30, retryInterval = 100) { | ||
function waitForScannerReadiness(retryCount = 100, retryInterval = 100) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes a11y team told to retry for 10 sec other framework have same count. |
||
return new Promise(async (resolve, reject) => { | ||
let count = 0; | ||
const intervalID = setInterval(async () => { | ||
|
@@ -222,7 +231,8 @@ new Promise( (resolve, reject) => { | |
resolve("Scanner is not ready on the page after multiple retries. after run"); | ||
}); | ||
} | ||
} catch(er) { | ||
} catch(error) { | ||
browserStackLog(`Error in saving results with error: ${error.message}`); | ||
resolve() | ||
} | ||
|
||
|
@@ -254,32 +264,13 @@ const shouldScanForAccessibility = (attributes) => { | |
const included = includeTagArray.length === 0 || includeTags.some((include) => fullTestName.includes(include)); | ||
shouldScanTestForAccessibility = !excluded && included; | ||
} catch (error) { | ||
browserStackLog("Error while validating test case for accessibility before scanning. Error : ", error); | ||
browserStackLog(`Error while validating test case for accessibility before scanning. Error : ${error.message}`); | ||
} | ||
} | ||
|
||
return shouldScanTestForAccessibility; | ||
} | ||
|
||
Cypress.on('command:start', async (command) => { | ||
if(!command || !command.attributes) return; | ||
if(command.attributes.name == 'window' || command.attributes.name == 'then' || command.attributes.name == 'wrap') { | ||
return; | ||
} | ||
|
||
if (!commandsToWrap.includes(command.attributes.name)) return; | ||
|
||
const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest || Cypress.mocha.getRunner().suite.ctx._runnable; | ||
|
||
let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); | ||
if (!shouldScanTestForAccessibility) return; | ||
|
||
cy.window().then((win) => { | ||
browserStackLog('Performing scan form command ' + command.attributes.name); | ||
cy.wrap(performScan(win, {method: command.attributes.name}), {timeout: 30000}); | ||
}) | ||
}) | ||
|
||
afterEach(() => { | ||
const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest; | ||
cy.window().then(async (win) => { | ||
|
@@ -322,6 +313,7 @@ afterEach(() => { | |
}) | ||
|
||
} catch (er) { | ||
browserStackLog(`Error in saving results with error: ${er.message}`); | ||
} | ||
}) | ||
}); | ||
|
@@ -337,9 +329,11 @@ Cypress.Commands.add('performScan', () => { | |
} | ||
cy.window().then(async (win) => { | ||
browserStackLog(`Performing accessibility scan`); | ||
await performScan(win); | ||
cy.wrap(performScan(win), {timeout:40000}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sets timeout, which can break the test if mochaTimeout is less than 40s. should we also handle mocha timeout ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the response from performScan take less time no timeout will occur. Eventually if response does not come and mocha timeout occurs it should be considered as timeout. |
||
}); | ||
} catch {} | ||
} catch(error) { | ||
browserStackLog(`Error in performing scan with error: ${error.message}`); | ||
} | ||
}) | ||
|
||
Cypress.Commands.add('getAccessibilityResultsSummary', () => { | ||
|
@@ -355,7 +349,9 @@ Cypress.Commands.add('getAccessibilityResultsSummary', () => { | |
browserStackLog('Getting accessibility results summary'); | ||
return await getAccessibilityResultsSummary(win); | ||
}); | ||
} catch {} | ||
} catch(error) { | ||
browserStackLog(`Error in getting accessibilty results summary with error: ${error.message}`); | ||
} | ||
|
||
}); | ||
|
||
|
@@ -376,6 +372,7 @@ Cypress.Commands.add('getAccessibilityResults', () => { | |
return await getAccessibilityResults(win); | ||
}); | ||
|
||
} catch {} | ||
|
||
} catch(error) { | ||
browserStackLog(`Error in getting accessibilty results with error: ${error.message}`); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason for removing
scroll
from the list ?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scroll is not a default cypress function. This error was occuring.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this verified across all supported cy versions ?