axe-core-npm icon indicating copy to clipboard operation
axe-core-npm copied to clipboard

Possible to get computed style of the page before analysing?

Open rabbit0v0 opened this issue 2 years ago • 3 comments
trafficstars

Product: react

Expectation: Do accessibility test with the actual color of the whole page.

Actual: Getting the colors in css instead of the actual color on screen, leading to false negative result.

Motivation: To get computed style when testing in high contrast mode.


@axe-core/playwright: "4.4.5"

rabbit0v0 avatar Feb 22 '23 15:02 rabbit0v0

Thanks for the issue. Can you provide a url to the website this occurs on or some sample code that reproduces the issue? Without that I'm not sure there's much we can do.

straker avatar Feb 22 '23 16:02 straker

Thanks for the reply!

For now we set high contrast mode with await page.emulateMedia({ media: "screen", forcedColors: "active", colorScheme: "light" }); , and we are doing accessibility test with const results = await new AxeBuilder({ page }).analyze(); We are not passing the test with this violation below,

"failureSummary": "Fix any of the following: + Element has insufficient color contrast of 1.07 (foreground color: #ffff00, background color: #ffffff, font size: 9.0pt (12px), font weight: normal). Expected contrast ratio of 4.5:1", + "html": "First name is a required field.",

A screenshot of the span is here. image

The test fails because it retrieves the color from the css file where the color is set to yellow image

We wonder if there could be a way to test the actual color from the screen instead of just checking the color in css file :) Many thanks!

rabbit0v0 avatar Feb 22 '23 18:02 rabbit0v0

Thanks for the detailed response. I'm not sure there's much we can do. Axe gets the styles directly from window.getComputedStyles. It seems that puppeteer is not setting that when doing emulate media, but there isn't any other way we could read it. I can do some investigating and let you know what I find.

straker avatar Mar 07 '23 20:03 straker