From c8533e2d9f0f70cf38f971e9a47a0ba43d2209ff Mon Sep 17 00:00:00 2001 From: EugeniyKiyashko Date: Fri, 4 Dec 2026 18:23:13 +0400 Subject: [PATCH 1/2] Playwright(demos e2e): check accessibility in the screenshot tests, remove the light accessibility jobs --- .github/workflows/pr-filter-stubs.yml | 21 ---- .github/workflows/visual-tests-demos.yml | 11 +- apps/demos/README.md | 4 +- apps/demos/playwright.accessibility.config.ts | 3 +- apps/demos/testing/accessibility.spec.ts | 111 ++---------------- apps/demos/testing/common.spec.ts | 26 +++- .../visual-tests/playwright/accessibility.ts | 110 +++++++++++++++++ .../utils/visual-tests/playwright/const.ts | 2 - 8 files changed, 147 insertions(+), 141 deletions(-) create mode 100644 apps/demos/utils/visual-tests/playwright/accessibility.ts diff --git a/.github/workflows/pr-filter-stubs.yml b/.github/workflows/pr-filter-stubs.yml index b4b7a31873f8..d3c19458bcf4 100644 --- a/.github/workflows/pr-filter-stubs.yml +++ b/.github/workflows/pr-filter-stubs.yml @@ -301,13 +301,6 @@ jobs: runs-on: ubuntu-latest steps: - run: exit 1 - demos_visual_tests7: - name: 'jquery-accessibility-fluent.blue.light' - needs: [ stubChecksReady ] - if: false - runs-on: ubuntu-latest - steps: - - run: exit 1 demos_visual_tests16: name: 'jquery-accessibility-fluent.blue.dark' needs: [ stubChecksReady ] @@ -322,13 +315,6 @@ jobs: runs-on: ubuntu-latest steps: - run: exit 1 - demos_visual_tests18: - name: 'jquery-accessibility-material.blue.light' - needs: [ stubChecksReady ] - if: false - runs-on: ubuntu-latest - steps: - - run: exit 1 demos_visual_tests19: name: 'react(1/3)-screenshots-fluent.blue.light' needs: [ stubChecksReady ] @@ -490,13 +476,6 @@ jobs: runs-on: ubuntu-latest steps: - run: exit 1 - demos_visual_tests43: - name: 'jquery-accessibility-fluent-next.blue.light' - needs: [ stubChecksReady ] - if: false - runs-on: ubuntu-latest - steps: - - run: exit 1 demos_visual_tests44: name: 'jquery-accessibility-fluent-next.blue.dark' needs: [ stubChecksReady ] diff --git a/.github/workflows/visual-tests-demos.yml b/.github/workflows/visual-tests-demos.yml index 64c8d5d2ef15..62b7ec4e3599 100644 --- a/.github/workflows/visual-tests-demos.yml +++ b/.github/workflows/visual-tests-demos.yml @@ -419,9 +419,6 @@ jobs: - { STRATEGY: screenshots, THEME: fluent-next.blue.light, CONSTEL: jquery(1/3) } - { STRATEGY: screenshots, THEME: fluent-next.blue.light, CONSTEL: jquery(2/3) } - { STRATEGY: screenshots, THEME: fluent-next.blue.light, CONSTEL: jquery(3/3) } - - { STRATEGY: accessibility, THEME: material.blue.light, CONSTEL: jquery } - - { STRATEGY: accessibility, THEME: fluent.blue.light, CONSTEL: jquery } - - { STRATEGY: accessibility, THEME: fluent-next.blue.light, CONSTEL: jquery } - { STRATEGY: accessibility, THEME: material.blue.dark, CONSTEL: jquery } - { STRATEGY: accessibility, THEME: fluent.blue.dark, CONSTEL: jquery } - { STRATEGY: accessibility, THEME: fluent-next.blue.dark, CONSTEL: jquery } @@ -580,15 +577,11 @@ jobs: exit 1 fi - - name: Sanitize job name - if: ${{ failure() }} - run: echo "JOB_NAME=$(echo "${{ matrix.CONSTEL }}-${{ matrix.THEME }}" | tr '/' '-')" >> $GITHUB_ENV - - name: Copy accessibility report - if: always() && matrix.STRATEGY == 'accessibility' + if: always() uses: actions/upload-artifact@v7 with: - name: accessibility-reports-${{ env.JOB_NAME }}-${{ matrix.THEME }} + name: accessibility-reports-${{ env.PLAYWRIGHT_JOB_NAME }} path: apps/demos/testing/artifacts/axe-reports/* if-no-files-found: ignore diff --git a/apps/demos/README.md b/apps/demos/README.md index 433a4e62c106..9f58e56b6d7b 100644 --- a/apps/demos/README.md +++ b/apps/demos/README.md @@ -65,7 +65,7 @@ pnpm run convert-to-js "JSDemos/Demos/Diagram/**/React" The "Check generated JS demos" GitHub Action ensures that the React JavaScript and TypeScript sources remain in sync. ## Screenshot Tests -Every demo page is compared with an etalon in `testing/etalons` (`testing/common.spec.ts`), and the widget tests in `testing/widgets` click through some demos and compare the steps with their own etalons. Both run on [Playwright](https://playwright.dev/) for jQuery, React, Vue and Angular, as do the jQuery accessibility checks (`testing/accessibility.spec.ts`). +Every demo page is compared with an etalon in `testing/etalons` (`testing/common.spec.ts`), and the widget tests in `testing/widgets` click through some demos and compare the steps with their own etalons. Both run on [Playwright](https://playwright.dev/) for jQuery, React, Vue and Angular. The jQuery demo tests also check the page with axe (see [Accessibility Tests](#accessibility-tests)). One etalon serves all four frameworks of a demo, and it is recorded from the jQuery demo. A framework that draws a demo differently is not given an etalon of its own: find out why it differs and make the demo the same in every framework. @@ -192,7 +192,7 @@ A failed comparison uploads its `-expected`, `-actual` and `-diff` images with t ## Accessibility Tests -`testing/accessibility.spec.ts` checks the `.demo-container` of every jQuery demo with [axe](https://github.com/dequelabs/axe-core) on Playwright. Fluent-next themes run only the `color-contrast` rule. The rules switched off for a demo are listed in `getIgnoredRules` of the same file. CI runs the light and dark variants of fluent, material and fluent-next. +The `.demo-container` of every jQuery demo is checked with [axe](https://github.com/dequelabs/axe-core). In the themes with screenshot tests (the light fluent, material and fluent-next), `testing/common.spec.ts` runs the check on the page of the screenshot test, after the comparison; a demo without a screenshot test gets a test with the check alone. The dark themes have no screenshot tests, so CI checks them with `testing/accessibility.spec.ts`, which runs only axe in any theme. Fluent-next themes run only the `color-contrast` rule. The rules switched off for a demo are listed in `getIgnoredRules` of `utils/visual-tests/playwright/accessibility.ts`. Build DevExtreme as for the screenshot tests, then: diff --git a/apps/demos/playwright.accessibility.config.ts b/apps/demos/playwright.accessibility.config.ts index 64efd08873aa..a9449fd1982b 100644 --- a/apps/demos/playwright.accessibility.config.ts +++ b/apps/demos/playwright.accessibility.config.ts @@ -1,9 +1,8 @@ import { defineConfig } from '@playwright/test'; import baseConfig from './playwright.config'; -import { ACCESSIBILITY_VIEWPORT } from './utils/visual-tests/playwright/const'; export default defineConfig(baseConfig, { testMatch: 'accessibility.spec.ts', retries: 0, - use: { viewport: ACCESSIBILITY_VIEWPORT, trace: 'off', screenshot: 'off' }, + use: { trace: 'off', screenshot: 'off' }, }); diff --git a/apps/demos/testing/accessibility.spec.ts b/apps/demos/testing/accessibility.spec.ts index ecaf0893f1b9..b57a3d9772a2 100644 --- a/apps/demos/testing/accessibility.spec.ts +++ b/apps/demos/testing/accessibility.spec.ts @@ -1,11 +1,13 @@ import { readFileSync, rmSync } from 'fs'; import { join } from 'path'; -import AxeBuilder from '@axe-core/playwright'; import { expect, test } from '@playwright/test'; -import type { Page } from '@playwright/test'; import { FRAMEWORKS } from '../utils/visual-tests/matrix-test-core'; -import { isFluent, isMaterial } from '../utils/visual-tests/helpers/theme-utils'; -import { createMdReport } from '../utils/axe-reporter/reporter'; +import { + checkAccessibility, + createAxeBuilder, + findViolations, + hasAccessibilityCheck, +} from '../utils/visual-tests/playwright/accessibility'; import { mockApi } from '../utils/visual-tests/playwright/api-mocks'; import { BASE_URL, THEME } from '../utils/visual-tests/playwright/const'; import { @@ -15,115 +17,18 @@ import { } from '../utils/visual-tests/playwright/demo-page'; import { getDemos, loadDemo } from '../utils/visual-tests/playwright/demos'; -const COLOR_CONTRAST_RULE = 'color-contrast'; - -const isColorContrastOnly = THEME.startsWith('fluent-next'); - const DEMOS_ROOT = join(__dirname, '..'); -const getIgnoredRules = (testName: string): string[] => { - const ignoredRules: string[] = []; - - if ((isMaterial() || isFluent()) - && [ - // False positive: contrast rules do not apply to custom orange color - 'CardView-FieldTemplate', - // False positive: contrast rules do not apply to read-only editors on the custom option panel background - 'VectorMap-DynamicViewport', - ].includes(testName) - ) { - ignoredRules.push('color-contrast'); - } - - const specificRules: Record = { - 'Diagram-Adaptability': ['aria-dialog-name', 'label'], - 'Diagram-AdvancedDataBinding': ['aria-dialog-name', 'label'], - 'Diagram-Containers': ['aria-dialog-name', 'label'], - 'Diagram-CustomShapesWithIcons': ['aria-dialog-name', 'label'], - 'Diagram-CustomShapesWithTemplates': ['label'], - 'Diagram-CustomShapesWithTemplatesWithEditing': ['aria-dialog-name', 'label'], - 'Diagram-CustomShapesWithTexts': ['aria-dialog-name', 'label'], - 'Diagram-ImagesInShapes': ['aria-dialog-name', 'label'], - 'Diagram-ItemSelection': ['label'], - 'Diagram-NodesAndEdgesArrays': ['aria-dialog-name', 'label'], - 'Diagram-NodesArrayHierarchicalStructure': ['aria-dialog-name', 'label'], - 'Diagram-NodesArrayPlainStructure': ['aria-dialog-name', 'label'], - 'Diagram-OperationRestrictions': ['aria-dialog-name', 'label'], - 'Diagram-Overview': ['aria-dialog-name', 'label'], - 'Diagram-ReadOnly': ['label'], - 'Diagram-SimpleView': ['label'], - 'Diagram-UICustomization': ['aria-dialog-name', 'label'], - 'Diagram-WebAPIService': ['aria-dialog-name', 'label'], - - 'FileManager-BindingToEF': ['aria-command-name', 'empty-table-header', 'label'], - 'FileManager-BindingToFileSystem': ['aria-command-name', 'empty-table-header', 'label'], - 'FileManager-BindingToHierarchicalStructure': ['aria-command-name', 'empty-table-header', 'label'], - 'FileManager-CustomThumbnails': ['aria-allowed-attr', 'aria-command-name', 'image-alt', 'label'], - 'FileManager-Overview': ['aria-command-name', 'empty-table-header', 'label'], - 'FileManager-UICustomization': ['aria-command-name', 'empty-table-header', 'label'], - - 'Gantt-Appearance': ['aria-toggle-field-name'], - 'Gantt-ExportToPDF': ['aria-toggle-field-name'], - }; - - return [ - ...ignoredRules, - ...(specificRules[testName] || []), - ]; -}; - -const areAriaOwnsResolved = (): boolean => Array - .from(document.querySelectorAll('[aria-owns]')) - .every((element) => (element.getAttribute('aria-owns') ?? '') - .split(' ') - .every((id) => !id || document.getElementById(id))); - -const createAxeBuilder = (page: Page, ignoredRules: string[], colorContrastOnly: boolean): AxeBuilder => { - const builder = new AxeBuilder({ page }) - .include('.demo-container') - .setLegacyMode(); - - return colorContrastOnly - ? builder.withRules([COLOR_CONTRAST_RULE]) - : builder.disableRules(ignoredRules); -}; - -const findViolations = async ( - page: Page, - testName: string, - ignoredRules: string[], - colorContrastOnly: boolean, -): Promise => { - await page.waitForFunction(areAriaOwnsResolved); - - const results = await createAxeBuilder(page, ignoredRules, colorContrastOnly).analyze(); - - if (results.violations.length > 0) { - createMdReport({ testName, results }); - } - - return results.violations.map(({ id, impact, nodes }) => `${id} (${impact}): ${nodes.map(({ target }) => target.join(' ')).join(', ')}`); -}; - -const getPageTheme = (page: Page): Promise => page.evaluate( - () => window.DevExpress.ui.themes.current(), -); - test.describe(FRAMEWORKS.jquery, () => { getDemos(FRAMEWORKS.jquery).forEach((demo) => { - const ignoredRules = getIgnoredRules(demo.testName); - - if (isColorContrastOnly && ignoredRules.includes(COLOR_CONTRAST_RULE)) { return; } + if (!hasAccessibilityCheck(demo.testName)) { return; } test(demo.testName, async ({ page }) => { const pageErrors = await loadDemo(page, demo); expect(pageErrors, 'uncaught errors in the page').toEqual([]); - expect(await getPageTheme(page), 'theme of the page').toBe(THEME); - - const violations = await findViolations(page, demo.testName, ignoredRules, isColorContrastOnly); - expect(violations, 'accessibility violations').toEqual([]); + await checkAccessibility(page, demo.testName); }); }); }); diff --git a/apps/demos/testing/common.spec.ts b/apps/demos/testing/common.spec.ts index 9d31021fc875..561ecfa987ee 100644 --- a/apps/demos/testing/common.spec.ts +++ b/apps/demos/testing/common.spec.ts @@ -5,6 +5,7 @@ import { shouldSkipDemo, } from '../utils/visual-tests/matrix-test-core'; import { DEFAULT_THEME_NAME, getScreenshotName } from '../utils/visual-tests/helpers/theme-utils'; +import { checkAccessibility, hasAccessibilityCheck } from '../utils/visual-tests/playwright/accessibility'; import { THEME } from '../utils/visual-tests/playwright/const'; import { collectCspViolations, getConsoleMessages } from '../utils/visual-tests/playwright/demo-page'; import { CSP_LOAD_TEST_TIMEOUT, checkDemoLoadUnderCsp } from '../utils/visual-tests/playwright/csp-load'; @@ -32,9 +33,15 @@ Object.values(FRAMEWORKS).forEach((approach) => { const demos = listDemos(approach); const hasScreenshotTest = ({ demo, ignored }: ListedDemo): boolean => !ignored && !shouldSkipDemo(approach, demo.widgetName, demo.demoName, skippedTests); + // The jQuery demos are also checked with axe, on the page of the screenshot test. + const isAccessibilityChecked = ({ demo, ignored }: ListedDemo): boolean => approach === FRAMEWORKS.jquery + && !ignored + && hasAccessibilityCheck(demo.testName); test.describe(approach, () => { - demos.filter(hasScreenshotTest).forEach(({ demo }) => { + demos.filter(hasScreenshotTest).forEach((listed) => { + const { demo } = listed; + test(demo.testName, async ({ page, cspViolations }) => { const pageErrors = await loadDemo(page, demo, true); @@ -46,7 +53,22 @@ Object.values(FRAMEWORKS).forEach((approach) => { expect(consoleMessages, 'console errors and warnings').toEqual([]); expect(pageErrors, 'uncaught errors in the page').toEqual([]); - await expect(page).toHaveScreenshot([getScreenshotName(`${demo.testName}.png`, THEME)]); + // Soft, so that a changed screenshot does not hide the accessibility violations. + await expect.soft(page).toHaveScreenshot([getScreenshotName(`${demo.testName}.png`, THEME)]); + + if (isAccessibilityChecked(listed)) { + await checkAccessibility(page, demo.testName); + } + }); + }); + + demos.filter((listed) => !hasScreenshotTest(listed) && isAccessibilityChecked(listed)).forEach(({ demo }) => { + test(`${demo.testName} accessibility`, async ({ page }) => { + const pageErrors = await loadDemo(page, demo); + + expect(pageErrors, 'uncaught errors in the page').toEqual([]); + + await checkAccessibility(page, demo.testName); }); }); }); diff --git a/apps/demos/utils/visual-tests/playwright/accessibility.ts b/apps/demos/utils/visual-tests/playwright/accessibility.ts new file mode 100644 index 000000000000..75bcb754f7d3 --- /dev/null +++ b/apps/demos/utils/visual-tests/playwright/accessibility.ts @@ -0,0 +1,110 @@ +import AxeBuilder from '@axe-core/playwright'; +import { expect } from '@playwright/test'; +import type { Page } from '@playwright/test'; +import { createMdReport } from '../../axe-reporter/reporter'; +import { isFluent, isMaterial } from '../helpers/theme-utils'; +import { THEME } from './const'; + +const COLOR_CONTRAST_RULE = 'color-contrast'; + +const isColorContrastOnly = THEME.startsWith('fluent-next'); + +const getIgnoredRules = (testName: string): string[] => { + const ignoredRules: string[] = []; + + if ((isMaterial() || isFluent()) + && [ + // False positive: contrast rules do not apply to custom orange color + 'CardView-FieldTemplate', + // False positive: contrast rules do not apply to read-only editors on the custom option panel background + 'VectorMap-DynamicViewport', + ].includes(testName) + ) { + ignoredRules.push('color-contrast'); + } + + const specificRules: Record = { + 'Diagram-Adaptability': ['aria-dialog-name', 'label'], + 'Diagram-AdvancedDataBinding': ['aria-dialog-name', 'label'], + 'Diagram-Containers': ['aria-dialog-name', 'label'], + 'Diagram-CustomShapesWithIcons': ['aria-dialog-name', 'label'], + 'Diagram-CustomShapesWithTemplates': ['label'], + 'Diagram-CustomShapesWithTemplatesWithEditing': ['aria-dialog-name', 'label'], + 'Diagram-CustomShapesWithTexts': ['aria-dialog-name', 'label'], + 'Diagram-ImagesInShapes': ['aria-dialog-name', 'label'], + 'Diagram-ItemSelection': ['label'], + 'Diagram-NodesAndEdgesArrays': ['aria-dialog-name', 'label'], + 'Diagram-NodesArrayHierarchicalStructure': ['aria-dialog-name', 'label'], + 'Diagram-NodesArrayPlainStructure': ['aria-dialog-name', 'label'], + 'Diagram-OperationRestrictions': ['aria-dialog-name', 'label'], + 'Diagram-Overview': ['aria-dialog-name', 'label'], + 'Diagram-ReadOnly': ['label'], + 'Diagram-SimpleView': ['label'], + 'Diagram-UICustomization': ['aria-dialog-name', 'label'], + 'Diagram-WebAPIService': ['aria-dialog-name', 'label'], + + 'FileManager-BindingToEF': ['aria-command-name', 'empty-table-header', 'label'], + 'FileManager-BindingToFileSystem': ['aria-command-name', 'empty-table-header', 'label'], + 'FileManager-BindingToHierarchicalStructure': ['aria-command-name', 'empty-table-header', 'label'], + 'FileManager-CustomThumbnails': ['aria-allowed-attr', 'aria-command-name', 'image-alt', 'label'], + 'FileManager-Overview': ['aria-command-name', 'empty-table-header', 'label'], + 'FileManager-UICustomization': ['aria-command-name', 'empty-table-header', 'label'], + + 'Gantt-Appearance': ['aria-toggle-field-name'], + 'Gantt-ExportToPDF': ['aria-toggle-field-name'], + }; + + return [ + ...ignoredRules, + ...(specificRules[testName] || []), + ]; +}; + +const areAriaOwnsResolved = (): boolean => Array + .from(document.querySelectorAll('[aria-owns]')) + .every((element) => (element.getAttribute('aria-owns') ?? '') + .split(' ') + .every((id) => !id || document.getElementById(id))); + +export const createAxeBuilder = (page: Page, ignoredRules: string[], colorContrastOnly: boolean): AxeBuilder => { + const builder = new AxeBuilder({ page }) + .include('.demo-container') + .setLegacyMode(); + + return colorContrastOnly + ? builder.withRules([COLOR_CONTRAST_RULE]) + : builder.disableRules(ignoredRules); +}; + +export const findViolations = async ( + page: Page, + testName: string, + ignoredRules: string[], + colorContrastOnly: boolean, +): Promise => { + await page.waitForFunction(areAriaOwnsResolved); + + const results = await createAxeBuilder(page, ignoredRules, colorContrastOnly).analyze(); + + if (results.violations.length > 0) { + createMdReport({ testName, results }); + } + + return results.violations.map(({ id, impact, nodes }) => `${id} (${impact}): ${nodes.map(({ target }) => target.join(' ')).join(', ')}`); +}; + +const getPageTheme = (page: Page): Promise => page.evaluate( + () => window.DevExpress.ui.themes.current(), +); + +// In a theme that runs only the contrast rule, a demo that switches it off has nothing to check. +export const hasAccessibilityCheck = (testName: string): boolean => !isColorContrastOnly + || !getIgnoredRules(testName).includes(COLOR_CONTRAST_RULE); + +export async function checkAccessibility(page: Page, testName: string): Promise { + expect(await getPageTheme(page), 'theme of the page').toBe(THEME); + + const violations = await findViolations(page, testName, getIgnoredRules(testName), isColorContrastOnly); + + expect(violations, 'accessibility violations').toEqual([]); +} diff --git a/apps/demos/utils/visual-tests/playwright/const.ts b/apps/demos/utils/visual-tests/playwright/const.ts index ad210314d58b..ed4357f57a9d 100644 --- a/apps/demos/utils/visual-tests/playwright/const.ts +++ b/apps/demos/utils/visual-tests/playwright/const.ts @@ -6,6 +6,4 @@ export const BASE_URL = `http://127.0.0.1:${SERVER_PORT}`; export const VIEWPORT = { width: 1000, height: 800 }; -export const ACCESSIBILITY_VIEWPORT = { width: 1200, height: 713 }; - export const THEME = process.env.THEME || DEFAULT_THEME_NAME; From 682603ade25e8d03665df3bf8138a45d644bfc64 Mon Sep 17 00:00:00 2001 From: EugeniyKiyashko Date: Fri, 4 Dec 2026 23:19:42 +0400 Subject: [PATCH 2/2] Run the jQuery screenshot tests without the X display, as the accessibility tests --- .github/workflows/visual-tests-demos.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/visual-tests-demos.yml b/.github/workflows/visual-tests-demos.yml index d277b7df51b8..e74f925905ce 100644 --- a/.github/workflows/visual-tests-demos.yml +++ b/.github/workflows/visual-tests-demos.yml @@ -520,6 +520,9 @@ jobs: # The default blob name is built from the test paths only, so jobs that differ by theme or # shard alone would write the same zip and overwrite each other once merged. PLAYWRIGHT_BLOB_OUTPUT_NAME: report-${{ env.PLAYWRIGHT_JOB_NAME }}.zip + # With the agent's X display the Azure maps of Map-Markers and Map-Routes never draw their + # controls, and their accessibility tests wait for them. + DISPLAY: '' run: pnpm run test-playwright - name: Run Playwright accessibility tests (jQuery)