cypress-axe icon indicating copy to clipboard operation
cypress-axe copied to clipboard

how to config checkA11y for all tests

Open kitsguru opened this issue 1 year ago • 1 comments

I have a series of specs for different sections and modules of my app. I would like to configure checkA11y in one location for all specs.

This works within each test

cy.checkA11y(null, {
    rules: {
		'color-contrast': { enabled: false },
		'frame-title': { enabled: false },
		},
});

I tried to set the configuration in support/index.js but I get an error

beforeEach(function () {
	// runs before each test in the block
	cy.visit('/')
	cy.injectAxe()
	cy.configureAxe({
		rules: {
			'color-contrast': { enabled: false },
			'frame-title': { enabled: false },
		},
	})
});

I am unsure where to set this up correctly.

kitsguru avatar Mar 27 '23 16:03 kitsguru

In the support, folder create a file e.g say axe-cofig.js and in that file create an object like this

export const defaultAxeConfiguration = {
    rules:[ {
       id: 'color-contrast', enabled: true,
    }],
    disableOtherRules: true,
};

and write your beforeEach like this beforeEach(()=>{ cy.visit('/') cy.injectAxe() cy.configureAxe(defaultAxeConfiguration) })

aamir-yaseen-baba avatar Apr 14 '23 10:04 aamir-yaseen-baba