-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[APM] add cypress-axe to e2e tests to check A11y #126610
[APM] add cypress-axe to e2e tests to check A11y #126610
Conversation
Pinging @elastic/kibana-accessibility (Project:Accessibility) |
Pinging @elastic/apm-ui (Team:apm) |
@@ -93,6 +105,9 @@ describe('Dependencies', () => { | |||
cy.contains('a', 'postgresql').click({ force: true }); | |||
|
|||
cy.contains('h1', 'postgresql'); | |||
|
|||
// set skipFailures to true to not fail the test when there are accessibility failures | |||
checkA11y(true); |
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.
This should probably be in a separate it
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.
Just one comment about a best practice option for bumping code coverage. Thank you!
timeRange | ||
)}` | ||
); | ||
cy.contains('a[role="tab"]', 'Dependencies'); |
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.
If there is a second tab that can be interacted with, it'd be great to click on that tab and make a second checkA11y
call to bump code coverage.
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.
Hi @1Copenut, this is our first approach to the A11y checks in our pages, we are going to add more checks in the future for now we are just checking the first render and not the interactions.
APM Service Overview contains multiple tabs, it's good to know that we can bump the code coverage if we check A11y in all of them.
5487206
to
10d64a1
Compare
|
||
const axeConfig = { | ||
...AXE_CONFIG, | ||
rules: [...AXE_CONFIG.rules], |
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.
Isn't this the same with just using AXE_CONFIG
?
it('has no detectable a11y violations on load', () => { | ||
cy.visit(serviceTransactionsHref); | ||
cy.contains('a[role="tab"]', 'Transactions').should( | ||
'have.class', |
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.
We might want to avoid depending on eui
classes. If we need to check that a tab is selected, we could instead use aria-selected="true" for example.
runOnly: [...AXE_OPTIONS.runOnly, 'best-practice'], | ||
}; | ||
|
||
export const checkA11y = (skipFailures: boolean) => { |
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.
Could we wrap cy.checkA11y
in our own command instead of calling the function?
@@ -53,6 +54,12 @@ describe('When navigating to the service inventory', () => { | |||
cy.visit(serviceInventoryHref); | |||
}); | |||
|
|||
it('has no detectable a11y violations on load', () => { | |||
cy.contains('Services'); |
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.
Checking some text on the page could be included in another test as it's not specific to accessibility (same with other files)
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.
It shows an error if trying to call checkA11y()
directly
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.
You mean without having anything else in the test? What error do you get?
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.
I think cy.contains('Services');
is needed to wait for that element to be visible before running the a11y check. Would be better if this was more obvious from the code
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.
Many thanks for adding this! It's great that we now have automation for accessibility testing and we can start adding more to it! I've added some minor comments on the PR.
); | ||
cy.contains('a[role="tab"]', 'Dependencies'); | ||
// set skipFailures to true to not fail the test when there are accessibility failures | ||
checkA11y(true); |
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.
Let's make it clear what true
means:
checkA11y(true); | |
checkA11y({ skipFailures: true }); |
cy.injectAxe(); | ||
cy.configureAxe(axeConfig); | ||
const context = '.kbnAppWrapper'; // Scopes a11y checks to only our app | ||
cy.checkA11y(context, axeOptions, undefined, skipFailures); |
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.
What's undefined
?
I'd prefer this:
cy.checkA11y(context, axeOptions, undefined, skipFailures); | |
cy.checkA11y( { context, axeOptions, skipFailures }); |
But I assume that's out of our control.
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.
I can't change that unfortunately
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.
But we can get rid of the last two params when we don't need to add skipFailures
, I added it now until we fix the failures.
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.
@sqren The undefined
here is a placeholder for an optional violations callback function that ultimately would be passed to the axe-core lib. The cypress-axe docs do a good job unpacking the arguments if you're curious: https://www.npmjs.com/package/cypress-axe#user-content-parameters-on-cychecka11y-axerun
💚 Build SucceededMetrics [docs]
History
To update your PR or re-run it, just comment with: |
Added cypress-axe to e2e tests to check A11y
#104692
For now, we are going to set the parameter
skipFailures
totrue
, this will log the errors but won't make the test fails, issues to tackle the failures will be created afterwards