Skip to content

Commit c5210b5

Browse files
author
Sumit JAGOTA
committed
Added accessibility library and minor fixed
- implemented the Axe library in framework - minor fixes and cleanup
1 parent 50ea021 commit c5210b5

File tree

8 files changed

+217
-48
lines changed

8 files changed

+217
-48
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ node_modules/
55
allure-results/
66
allure-report/
77
html-report/
8+
practice.ts

base_fwk/common/CommonScenario.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import AxeBuilder from "@axe-core/playwright";
12
import { test, expect, Page, TestInfo } from "@playwright/test";
23
export class CommonScenario {
34
private myMap = new Map<string, string>();
@@ -26,4 +27,14 @@ export class CommonScenario {
2627
getValue(key: string) {
2728
return this.myMap.get(key);
2829
}
30+
31+
async a11yAnalysis() {
32+
const accessibilityScanResults = await new AxeBuilder({ page: this.page }).analyze(); // 4
33+
const issues = accessibilityScanResults.violations.length;
34+
console.log("a11y issues found: " + issues);
35+
await this.testinfo.attach('accessibility-scan-results', {
36+
body: JSON.stringify(accessibilityScanResults, null, 2),
37+
contentType: 'application/json'
38+
});
39+
}
2940
}

package-lock.json

Lines changed: 198 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"license": "ISC",
1818
"devDependencies": {
1919
"@playwright/test": "^1.29",
20-
"allure-playwright": "^2.0.0-beta.20"
20+
"allure-playwright": "^2.0.0-beta.20",
21+
"@axe-core/playwright": "4.6.0"
2122
}
2223
}

pageObjects/DashBoardPage/DashBoardPage.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import { locators } from "./DashBoardLocators";
66
export class DashboardPage extends CommonPage {
77
constructor(public page: Page, readonly scenario: CommonScenario) {
88
super(page, scenario);
9-
this.page = page;
10-
this.scenario = scenario;
119
}
12-
10+
1311
async searchProductAddCart(productName, testInfo) {
1412
const product = await this.page.locator(locators.products, { hasText: productName });
1513
const addCartButton = await product.locator("button", { hasText: " Add To Cart" });

pageObjects/LoginPage/LoginPage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import AxeBuilder from "@axe-core/playwright";
12
import { expect, Page, } from "@playwright/test";
23
import { CommonPage } from "../../base_fwk/common/CommonPage";
34
import { CommonScenario } from "../../base_fwk/common/CommonScenario";
@@ -12,6 +13,7 @@ export class LoginPage extends CommonPage {
1213
async goTo() {
1314
await this.page.goto(testData.qa);
1415
await this.page.waitForLoadState("domcontentloaded");
16+
await this.scenario.a11yAnalysis();
1517
}
1618

1719
async validLogin(username, password) {

playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const config: PlaywrightTestConfig = {
2929
/* Retry on CI only */
3030
retries: process.env.CI ? 2 : 0,
3131
/* Opt out of parallel tests on CI. */
32-
workers: process.env.CI ? 1 : 2,
32+
workers: process.env.CI ? 1 : 3,
3333
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
3434
reporter: [
3535
['dot'],

tests/fwkTesting.spec.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import AxeBuilder from "@axe-core/playwright";
12
import test, { expect } from "../base_fwk/fixtures/baseTest"
23
import { OrdersReviewPage } from "../pageObjects/OrdersReviewPage/OrdersReviewPage";
34
//import { POManager } from "../pageObjects/POManager"
@@ -8,28 +9,8 @@ import { testData } from "./testData";
89
test.describe('two tests', () => {
910
console.log("in describe from spec file");
1011
test("first playwright test12", async ({ page, context, browser, loginPage, dashboardPage, cartPage, ordersReviewPage, ordersHistoryPage }) => {
11-
// test("first playwright test12", async ({ }) => {
12-
// test("first playwright test12", async ({ page }) => {
1312
console.log("test start")
14-
// await page.goto('https://example.com');
15-
16-
17-
18-
// await page.route("https://rahulshettyacademy.com/api/ecom/product/get-all-products", async (route) => {
19-
// //console.log("<<" + route.request().postData())
20-
// const response = await route.fetch();
21-
// const json = await response.json();
22-
// json.data[0].productName = "supermannnnnn";
23-
// json.data[1].productName = "batmann";
24-
25-
// await route.fulfill({ response, json });
26-
// })
27-
2813
await loginPage.goTo();
29-
// await loginPage.validLogin(testData.username, testData.password);
30-
// await page.waitForResponse("https://rahulshettyacademy.com/api/ecom/product/get-all-products");
31-
32-
3314
console.log("test ends")
3415

3516
// await loginPage.validLogin(testConfig.username, testConfig.password);
@@ -40,14 +21,7 @@ test.describe('two tests', () => {
4021
// await ordersReviewPage.testOrdersReviewPage();
4122
// const value = await dashboardPage.getValue("sumit");
4223
// console.log(value);
43-
44-
45-
46-
4724
});
4825

4926
});
5027

51-
52-
53-
// });

0 commit comments

Comments
 (0)