Skip to content

Commit d67d910

Browse files
committed
POM Structure change
1 parent 176309d commit d67d910

37 files changed

+1493
-1074
lines changed

Diff for: CustomReporterConfig.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ const logger = winston.createLogger({
66
level: 'info',
77
format: winston.format.json(),
88
transports: [
9-
// - Write all logs with importance level of `info` or less than it
10-
new winston.transports.File({ filename: 'logs/info.log', level: 'info' }),
9+
// - Write all logs with importance level of `info` or less than it
10+
new winston.transports.File({ filename: 'logs/info.log', level: 'info' }),
1111
],
12-
});
12+
});
1313

14-
// Writes logs to console
15-
logger.add(console);
14+
// Writes logs to console
15+
logger.add(console);
1616

1717
export default class CustomReporterConfig implements Reporter {
1818

Diff for: Dockerfile

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
FROM mcr.microsoft.com/playwright:v1.22.0-focal
1+
FROM mcr.microsoft.com/playwright:v1.31.0-focal
22

33
WORKDIR /app
44

55
COPY package.json package-lock.json ./
66

77
RUN npm ci
88

9+
#Install chrome on Docker container
10+
RUN npx playwright install chrome
11+
912
COPY . .
1013

1114
#Adding a non root User named "turing"
@@ -17,4 +20,4 @@ RUN chown -R turing /app
1720
#Switching from root user to non-root user(turing)
1821
USER turing
1922

20-
CMD ["npx","cross-env","ENV=qa","npm","run","test:serial"]
23+
CMD npx cross-env ENV=qa npm run test:serial

Diff for: README.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Bonus:
5555

5656
- Supports PostgresSQL using 'pg' module.
5757
- Supports Excel File Read/Write using 'excel-js' module.
58-
- Converts HTL Reports to Zip format which can shared across.
58+
- Converts HTML Reports to Zip format which can shared across.
5959

6060
### Built With
6161

@@ -108,6 +108,11 @@ https://github.com/akshayp7/playwright-typescipt-playwright-test.git
108108
```sh
109109
npm install
110110
```
111+
3. For first time installation run below command to download required browsers
112+
113+
```sh
114+
npx playwright install
115+
```
111116

112117
<!-- USAGE EXAMPLES-->
113118

@@ -267,13 +272,13 @@ docker run --name playContainer playtest
267272
- If you want to run a different test or provide custom command, Go to Dockerfile and edit the last line which is CMD section. The below sample runs test cases serially on QA environment.
268273
Once you have edited the CMD section we have to follow Step 1 to build a new image and ten run the Container from that image.
269274
```JS
270-
CMD ["npx","cross-env","ENV=qa","npm","run","test:serial"]
275+
CMD npx cross-env ENV=qa npm run test:serial
271276
```
272277

273278
## Lighthouse
274279
Lighthouse is an open-source, automated tool for improving the quality of web pages. You can run it against any web page, public or requiring authentication. It has audits for performance, accessibility, progressive web apps, SEO and more.
275-
I have configure Lighthouse for Performance in my Project.
276-
- To configure Lighthouse navigate to "Lighthouse.js" and replace "https://www.google.com" with desired URL to test.
280+
I have configure Lighthouse for Performance in my Project. Please use version 9.6.8 as later versions are not compatible.
281+
- To configure Lighthouse navigate to "tests/lighthouse/Lighthouse.js" and replace "https://www.google.com" with desired URL to test.
277282
- To run test on Mobile devices, comment out desktop mode config line and uncomment the config line written for mobile devices, Default Device is Moto G4
278283
- To run Lighhouse test use below command, reports will be generated in htnl format in root directory with name "LighthouseReport.html"
279284
```JS
@@ -285,4 +290,4 @@ npm run lighthouse
285290
[overall-report-screenshot]: ReadMeImages/OverallReport.PNG
286291
[detailed-report-screenshot]: ReadMeImages/DetailedReport.PNG
287292
[failure-report-screenshot]: ReadMeImages/FailureReport.PNG
288-
[sonar-report-screenshot]: ReadMeImages/SonarReport.PNG
293+
[sonar-report-screenshot]: ReadMeImages/SonarReport.PNG

Diff for: lib/BaseTest.ts

+25-16
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
11
import { test as baseTest } from '@playwright/test';
22
import { LoginPage } from '@pages/LoginPage';
3-
import { MyAccountPage } from '@pages/MyAccountPage';
4-
import { MyAddressesPage } from '@pages/MyAddressesPage'
5-
import { MyPersonalInformationPage } from '@pages/MyPersonalInformationPage';
3+
import { ElementsPage } from '@pages/ElementsPage';
4+
import { AlertsFrameWindowsPage } from '@pages/AlertsFrameWindowsPage';
5+
import { WidgetsPage } from '@pages/WidgetsPage';
6+
import { InteractionsPage } from '@pages/InteractionsPage';
7+
import { WebActions } from '@lib/WebActions';
68

79
const test = baseTest.extend<{
10+
webActions: WebActions;
811
loginPage: LoginPage;
9-
myAccountPage: MyAccountPage;
10-
myAddressesPage: MyAddressesPage;
11-
myPersonalInformationPage: MyPersonalInformationPage;
12-
12+
elementsPage: ElementsPage;
13+
alertsFrameWindowsPage: AlertsFrameWindowsPage;
14+
widgetsPage: WidgetsPage;
15+
interactionsPage: InteractionsPage;
1316
}>({
14-
loginPage: async ({ page }, use) => {
15-
await use(new LoginPage(page));
17+
webActions: async ({ page, context }, use) => {
18+
await use(new WebActions(page, context));
19+
},
20+
loginPage: async ({ page, context }, use) => {
21+
await use(new LoginPage(page, context));
22+
},
23+
elementsPage: async ({ page, context }, use) => {
24+
await use(new ElementsPage(page, context));
1625
},
17-
myAccountPage: async ({ page }, use) => {
18-
await use(new MyAccountPage(page));
26+
alertsFrameWindowsPage: async ({ page, context }, use) => {
27+
await use(new AlertsFrameWindowsPage(page, context));
1928
},
20-
myAddressesPage: async ({ page }, use) => {
21-
await use(new MyAddressesPage(page));
29+
widgetsPage: async ({ page, context }, use) => {
30+
await use(new WidgetsPage(page, context));
2231
},
23-
myPersonalInformationPage: async ({ page }, use) => {
24-
await use(new MyPersonalInformationPage(page));
32+
interactionsPage: async ({ page, context }, use) => {
33+
await use(new InteractionsPage(page, context));
2534
}
26-
});
35+
})
2736

2837
export default test;

Diff for: lib/WebActions.ts

+6-104
Original file line numberDiff line numberDiff line change
@@ -4,92 +4,38 @@ import type { Page } from '@playwright/test';
44
import { BrowserContext, expect } from '@playwright/test';
55
import { Workbook } from 'exceljs';
66
import { testConfig } from '../testConfig';
7-
import path from 'path';
8-
const waitForElement = testConfig.waitForElement;
97

108
export class WebActions {
119
readonly page: Page;
10+
readonly context: BrowserContext;
1211

13-
constructor(page: Page) {
12+
constructor(page: Page, context: BrowserContext) {
1413
this.page = page;
15-
}
16-
17-
async navigateToURL(url: string) {
18-
this.page.goto(url);
14+
this.context = context;
1915
}
2016

2117
async decipherPassword(): Promise<string> {
2218
const key = `SECRET`;
2319
//ENCRYPT
24-
// const cipher = CryptoJS.AES.encrypt('demouat',key);
20+
// const cipher = CryptoJS.AES.encrypt('Demouat@09',key);
2521
// console.log(cipher.toString());
2622
return CryptoJS.AES.decrypt(testConfig.password, key).toString(CryptoJS.enc.Utf8);
2723
}
2824

29-
async waitForPageNavigation(event: string): Promise<void> {
30-
switch (event.toLowerCase()) {
31-
case `networkidle`:
32-
await this.page.waitForNavigation({ waitUntil: `networkidle`, timeout: waitForElement });
33-
break;
34-
case `load`:
35-
await this.page.waitForNavigation({ waitUntil: `load`, timeout: waitForElement });
36-
break;
37-
case `domcontentloaded`:
38-
await this.page.waitForNavigation({ waitUntil: `domcontentloaded`, timeout: waitForElement });
39-
}
40-
}
41-
4225
async delay(time: number): Promise<void> {
4326
return new Promise(function (resolve) {
4427
setTimeout(resolve, time);
4528
});
4629
}
4730

48-
async clickElement(locator: string): Promise<void> {
49-
await this.page.click(locator);
31+
async clickByText(text: string): Promise<void> {
32+
await this.page.getByText(text, { exact: true }).click(); //Matches locator with exact text and clicks
5033
}
5134

5235
async clickElementJS(locator: string): Promise<void> {
5336
await this.page.$eval(locator, (element: HTMLElement) => element.click());
5437
}
5538

56-
async boundingBoxClickElement(locator: string): Promise<void> {
57-
await this.delay(1000);
58-
const elementHandle = await this.page.$(locator);
59-
const box = await elementHandle.boundingBox();
60-
await this.page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
61-
}
62-
63-
async enterElementText(locator: string, text: string): Promise<void> {
64-
await this.page.fill(locator, text);
65-
}
66-
67-
async dragAndDrop(dragElementLocator: string, dropElementLocator: string): Promise<void> {
68-
await this.page.dragAndDrop(dragElementLocator, dropElementLocator);
69-
}
70-
71-
async selectOptionFromDropdown(locator: string, option: string): Promise<void> {
72-
const selectDropDownLocator = await this.page.$(locator);
73-
selectDropDownLocator.type(option);
74-
}
75-
76-
async getTextFromWebElements(locator: string): Promise<string[]> {
77-
return this.page.$$eval(locator, elements => elements.map(item => item.textContent.trim()));
78-
}
79-
80-
async downloadFile(locator: string): Promise<string> {
81-
const [download] = await Promise.all([
82-
this.page.waitForEvent(`download`),
83-
this.page.click(locator)
84-
]);
85-
await download.saveAs(path.join(__dirname, `../Downloads`, download.suggestedFilename()));
86-
return download.suggestedFilename();
87-
}
88-
89-
async keyPress(locator: string, key: string): Promise<void> {
90-
this.page.press(locator, key);
91-
}
92-
9339
async readDataFromExcel(fileName: string, sheetName: string, rowNum: number, cellNum: number): Promise<string> {
9440
const workbook = new Workbook();
9541
return workbook.xlsx.readFile(`./Downloads/${fileName}`).then(function () {
@@ -108,48 +54,4 @@ export class WebActions {
10854
throw error;
10955
});
11056
}
111-
112-
async verifyElementText(locator: string, text: string): Promise<void> {
113-
const textValue = await this.page.textContent(locator);
114-
expect(textValue.trim()).toBe(text);
115-
}
116-
117-
118-
async verifyNewWindowUrlAndClick(context: BrowserContext, newWindowLocator: string, urlText: string,clickOnNewWindowLocator:string): Promise<void> {
119-
const [newPage] = await Promise.all([
120-
context.waitForEvent('page'),
121-
this.page.click(newWindowLocator)
122-
])
123-
await newPage.waitForLoadState();
124-
expect(newPage.url()).toContain(urlText);
125-
await newPage.click(clickOnNewWindowLocator);
126-
await newPage.close();
127-
}
128-
129-
async verifyElementContainsText(locator: string, text: string): Promise<void> {
130-
await expect(this.page.locator(locator)).toContainText(text);
131-
}
132-
133-
async verifyJSElementValue(locator: string, text: string): Promise<void> {
134-
const textValue = await this.page.$eval(locator, (element: HTMLInputElement) => element.value);
135-
expect(textValue.trim()).toBe(text);
136-
}
137-
138-
async verifyElementAttribute(locator: string, attribute: string, value: string): Promise<void> {
139-
const textValue = await this.page.getAttribute(locator, attribute);
140-
expect(textValue.trim()).toBe(value);
141-
}
142-
143-
async verifyElementIsDisplayed(locator: string, errorMessage: string): Promise<void> {
144-
await this.page.waitForSelector(locator, { state: `visible`, timeout: waitForElement })
145-
.catch(() => { throw new Error(`${errorMessage}`); });
146-
}
147-
148-
async expectToBeTrue(status: boolean, errorMessage: string): Promise<void> {
149-
expect(status, `${errorMessage}`).toBe(true);
150-
}
151-
152-
async expectToBeValue(expectedValue: string, actualValue: string, errorMessage: string): Promise<void> {
153-
expect(expectedValue.trim(), `${errorMessage}`).toBe(actualValue);
154-
}
15557
}

0 commit comments

Comments
 (0)