Skip to content

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

Merged
merged 9 commits into from
Dec 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
SDK-1884: added error debugging logs.
  • Loading branch information
osho-20 committed Dec 3, 2024
commit 02ea36a3b4007a89505a0259ce75c3f95439fa8a
39 changes: 22 additions & 17 deletions bin/accessibility-automation/cypress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Copy link
Contributor

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 ?

Copy link
Collaborator Author

@osho-20 osho-20 Dec 4, 2024

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.

Copy link
Contributor

@sauravdas1997 sauravdas1997 Dec 5, 2024

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 ?

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) => {
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -254,24 +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;
}

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));
});
});


afterEach(() => {
const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest;
cy.window().then(async (win) => {
Expand Down Expand Up @@ -314,6 +313,7 @@ afterEach(() => {
})

} catch (er) {
browserStackLog(`Error in saving results with error: ${er.message}`);
}
})
});
Expand All @@ -331,7 +331,9 @@ Cypress.Commands.add('performScan', () => {
browserStackLog(`Performing accessibility scan`);
cy.wrap(performScan(win), {timeout:40000});
Copy link
Contributor

@sauravdas1997 sauravdas1997 Dec 4, 2024

Choose a reason for hiding this comment

The 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 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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', () => {
Expand All @@ -347,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}`);
}

});

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

} catch {}

} catch(error) {
browserStackLog(`Error in getting accessibilty results with error: ${error.message}`);
}
});
Loading