Skip to content

Commit 54c2a8d

Browse files
general accessibility tests
1 parent be57c2f commit 54c2a8d

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: Accessibility tests for main pages
2+
3+
on:
4+
push:
5+
branches:
6+
- prod
7+
workflow_dispatch:
8+
9+
jobs:
10+
run-accessibility-tests:
11+
runs-on: ubuntu-latest
12+
container: cypress/included:13.9.0
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Cleanup previous results
18+
run: rm -rf /__w/openliberty.io/openliberty.io/src/test/cypressjs/results/*
19+
20+
- name: Cleanup Cypress Cache
21+
run: rm -rf ~/.cache/Cypress
22+
23+
- name: Run first test file
24+
run: |
25+
cypress run --browser chrome --headed \
26+
--env JDK_VERSION="1.8.0_311" \
27+
--config-file /__w/openliberty.io/openliberty.io/src/test/cypressjs/cypress.config.js \
28+
--spec "/__w/openliberty.io/openliberty.io/src/test/cypressjs/cypress/e2e/generalAllyTest.cy.js"
29+
- name: Debug - List files
30+
run: ls -R /__w/openliberty.io/openliberty.io/src/test/cypressjs/results
31+
32+
- name: Setup Node.js
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version: 20
36+
37+
- name: Install zip utility
38+
run: apt-get update && apt-get install -y zip
39+
40+
- name: Analyze Accessibility Results
41+
id: analyze_results
42+
run: |
43+
node <<'EOF'
44+
import fs from 'fs';
45+
import path from 'path';
46+
import { execSync } from 'child_process';
47+
48+
const resultsDir = '/__w/openliberty.io/openliberty.io/src/test/cypressjs/results/OL.io';
49+
if (!fs.existsSync(resultsDir)) {
50+
console.log('No results directory found.');
51+
process.exit(0);
52+
}
53+
54+
const files = fs.readdirSync(resultsDir).filter(f => f.endsWith('.json'));
55+
const violatingFiles = [];
56+
57+
for (const file of files) {
58+
const filePath = path.join(resultsDir, file);
59+
try {
60+
const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
61+
const violations = data?.summary?.counts?.violation ?? 0;
62+
if (violations > 0) violatingFiles.push(file);
63+
} catch (err) {
64+
console.error(`Error parsing ${file}:`, err);
65+
}
66+
}
67+
68+
if (violatingFiles.length > 0) {
69+
// Create ZIP of violating files for download
70+
const zipName = 'violations_only.zip';
71+
const fileList = violatingFiles.map(f => path.join(resultsDir, f)).join(' ');
72+
execSync(`zip -j ${zipName} ${fileList}`);
73+
74+
// Store output for next steps
75+
const fileNamesWithoutExt = violatingFiles.map(f => path.basename(f, '.json')).join(', ');
76+
fs.appendFileSync(process.env.GITHUB_OUTPUT, `violations=${fileNamesWithoutExt}\n`);
77+
fs.appendFileSync(process.env.GITHUB_OUTPUT, `zip_file=${zipName}\n`);
78+
console.log('Violations found in:', fileNamesWithoutExt);
79+
} else {
80+
console.log('No accessibility violations found.');
81+
}
82+
EOF
83+
84+
- name: Upload Violations ZIP
85+
if: steps.analyze_results.outputs.zip_file != ''
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: accessibility-violations
89+
path: ${{ steps.analyze_results.outputs.zip_file }}
90+
retention-days: 7
91+
92+
- name: Generate Issue Content
93+
if: steps.analyze_results.outputs.violations != ''
94+
run: |
95+
echo "### Accessibility Violations Detected" > issue.md
96+
echo "" >> issue.md
97+
echo "Cypress has reported accessibility violations on the following pages:" >> issue.md
98+
echo "${{ steps.analyze_results.outputs.violations }}" >> issue.md
99+
echo "" >> issue.md
100+
echo "[Download violating result files (ZIP)](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> issue.md
101+
echo "" >> issue.md
102+
echo "_This issue was automatically generated by the accessibility testing workflow._" >> issue.md
103+
104+
- name: Create GitHub Issue
105+
if: steps.analyze_results.outputs.violations != ''
106+
uses: peter-evans/create-issue-from-file@v5
107+
with:
108+
title: "Accessibility violations detected in main pages"
109+
content-filepath: issue.md
110+
labels: a11y
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
describe('Accessibility tests for main pages', () => {
2+
it('Testing Home page',()=>{
3+
cy.visit('https://openliberty.io/');
4+
cy.getCompliance('./OL.io/home');
5+
});
6+
it('Testing Start page',()=>{
7+
cy.visit('https://openliberty.io/start/');
8+
cy.getCompliance('./OL.io/start');
9+
});
10+
it('Testing Guides page',()=>{
11+
cy.visit('https://openliberty.io/guides/');
12+
cy.getCompliance('./OL.io/guides');
13+
});
14+
it('Testing Blogs page',()=>{
15+
cy.visit('https://openliberty.io/blogs/');
16+
cy.getCompliance('./OL.io/blogs');
17+
})
18+
it('Testing Support page',()=>{
19+
cy.visit('https://openliberty.io/support/');
20+
cy.getCompliance('./OL.io/support');
21+
})
22+
it('Testing Docs page',()=>{
23+
cy.visit('https://openliberty.io/docs/latest/overview.html');
24+
cy.getCompliance('./OL.io/docs');
25+
})
26+
});

0 commit comments

Comments
 (0)