Skip to content

Commit f17271a

Browse files
committed
AccessibilityTestCaseAdded
1 parent 35b0284 commit f17271a

File tree

7 files changed

+63
-4
lines changed

7 files changed

+63
-4
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ npm run test:ui --ENV="qa"
230230
```
231231
24. For Extracting text from PDF we are using `pdfjs-dist-es5` library. You can run the test case `PdfToText.test.ts` to verify contents of PDF file. `getPDFText()` method in `lib/WebActions.ts` class is used for extracting text from PDF file.
232232

233+
25. Accessibility test case is written in `tests/accessibility/Axe.test.ts`, to run this test use the command
234+
```JS
235+
npm run test:accessibility --ENV="qa"
236+
```
237+
233238
## Reports
234239

235240
- <b>Overall Report</b>

lib/BaseTest.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { test as baseTest } from '@playwright/test';
1+
import { TestInfo, test as baseTest } from '@playwright/test';
22
import { LoginPage } from '@pages/LoginPage';
33
import { ElementsPage } from '@pages/ElementsPage';
44
import { AlertsFrameWindowsPage } from '@pages/AlertsFrameWindowsPage';
55
import { WidgetsPage } from '@pages/WidgetsPage';
66
import { InteractionsPage } from '@pages/InteractionsPage';
77
import { WebActions } from '@lib/WebActions';
8+
import AxeBuilder from '@axe-core/playwright';
89

910
const test = baseTest.extend<{
1011
webActions: WebActions;
@@ -13,6 +14,8 @@ const test = baseTest.extend<{
1314
alertsFrameWindowsPage: AlertsFrameWindowsPage;
1415
widgetsPage: WidgetsPage;
1516
interactionsPage: InteractionsPage;
17+
makeAxeBuilder: AxeBuilder;
18+
testInfo: TestInfo;
1619
}>({
1720
webActions: async ({ page, context }, use) => {
1821
await use(new WebActions(page, context));
@@ -31,6 +34,11 @@ const test = baseTest.extend<{
3134
},
3235
interactionsPage: async ({ page, context }, use) => {
3336
await use(new InteractionsPage(page, context));
37+
},
38+
makeAxeBuilder: async ({ page }, use) => {
39+
await use(new AxeBuilder({ page })
40+
.withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa'])
41+
.exclude('#commonly-reused-element-with-known-issue'));
3442
}
3543
})
3644

package-lock.json

+35
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"test:visual": "npx playwright test visualComparision.test.ts --project=Chrome",
1616
"test:device": "npx playwright test Emulation.test.ts --project=Device",
1717
"allureReport": "allure serve",
18-
"lighthouse": "node tests/lighthouse/Lighthouse.js"
18+
"lighthouse": "node tests/lighthouse/Lighthouse.js",
19+
"test:accessibility": "npx playwright test Axe.test.ts --project=Chrome"
1920
},
2021
"repository": {
2122
"type": "git",
@@ -24,6 +25,7 @@
2425
"author": "Akshay Pai",
2526
"license": "MIT",
2627
"dependencies": {
28+
"@axe-core/playwright": "^4.8.2",
2729
"@playwright/test": "^1.40.1",
2830
"@types/adm-zip": "^0.5.5",
2931
"@types/crypto-js": "^4.2.1",
@@ -42,4 +44,4 @@
4244
"typescript": "^5.3.2",
4345
"winston": "^3.11.0"
4446
}
45-
}
47+
}

playwright.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { testConfig } from './testConfig';
33
const ENV = process.env.npm_config_ENV;
44

55
if (!ENV || ![`qa`, `dev`, `qaApi`, `devApi`].includes(ENV)) {
6-
console.log(`Please provide a correct environment value like "npx cross-env ENV=qa|dev|qaApi|devApi"`);
6+
console.log(`Please provide a correct environment value after command like "--ENV=qa|dev|qaApi|devApi"`);
77
process.exit();
88
}
99

tests/accessibility/Axe.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import test from '@lib/BaseTest';
2+
import { expect } from "@playwright/test";
3+
4+
test(`Verify Page Accessibility`, async ({ page, makeAxeBuilder }) => {
5+
await page.goto('https://google.com/');
6+
const accessibilityScanResults = await makeAxeBuilder.analyze();
7+
// Automatically uses the shared AxeBuilder configuration,
8+
expect(accessibilityScanResults.violations).toEqual([]);
9+
});

0 commit comments

Comments
 (0)