Skip to content

Commit a35a1ad

Browse files
committed
POM
1 parent 15e8e6c commit a35a1ad

File tree

9 files changed

+84
-25
lines changed

9 files changed

+84
-25
lines changed

lib/BasePages.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { LoginPage } from '../pageFactory/pageRepository/LoginPage';
2+
import { test as baseTest } from '@playwright/test';
3+
4+
const test = baseTest.extend<{
5+
loginPage: LoginPage;
6+
7+
}>({
8+
loginPage: async ({ page }, use) => {
9+
await use(new LoginPage(page));
10+
}
11+
});
12+
13+
export default test;

lib/WebActions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class WebActions {
1818
async decipherPassword(): Promise<string> {
1919
const key = `SECRET`;
2020
//ENCRYPT
21-
// const cipher = CryptoJS.AES.encrypt('Pasword',key);
21+
// const cipher = CryptoJS.AES.encrypt('demouser',key);
2222
// console.log(cipher.toString());
2323
return CryptoJS.AES.decrypt(loginData.password, key).toString(CryptoJS.enc.Utf8);
2424
}
@@ -149,7 +149,7 @@ export class WebActions {
149149
throw new Error(`${errorMessage}`);
150150
}
151151
}
152-
152+
153153
async expectToBeValue(expectedValue: string, actualValue: string, errorMessage: string): Promise<void> {
154154
try {
155155
expect(expectedValue.trim()).toBe(actualValue);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "npx playwright test",
8-
"test:single": "npx playwright test GoogleSearch.test.ts --project=Chrome",
8+
"test:single": "npx playwright test Login.test.ts --project=Chrome",
99
"test:parallel": "npx playwright test --grep @Regression --project=Chrome",
1010
"test:serial": "npx playwright test --grep @Regression --workers=1 --project=Chrome",
1111
"test:api": "npx playwright test --grep @api --workers=1 --project=Chrome",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export class LoginPageObjects {
2+
EMAIL_EDITBOX_XPATH = `//input[@name=' Femail']`;
3+
PASSWORD_EDITBOX_XPATH = `//input[@name='password']`;
4+
LOGIN_BUTTON_XPATH = `//span[text()='Login']`;
5+
6+
7+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { LoginPageObjects } from "../objectRepository/LoginPageObjects";
2+
import { WebActions } from "../../lib/WebActions";
3+
import type { Page } from 'playwright';
4+
import fs from 'fs';
5+
6+
const loginData = JSON.parse(fs.readFileSync('./testData.json', 'utf-8'));
7+
8+
let webActions: WebActions;
9+
10+
export class LoginPage {
11+
readonly page: Page;
12+
13+
constructor(page: Page) {
14+
this.page = page;
15+
webActions = new WebActions(this.page);
16+
}
17+
18+
loginPageObjects = new LoginPageObjects();
19+
20+
async navigateToURL() {
21+
await this.page.goto(loginData.URL);
22+
}
23+
24+
async loginToApplication() {
25+
const decipherPassword = await webActions.decipherPassword();
26+
await this.page.fill(this.loginPageObjects.EMAIL_EDITBOX_XPATH, loginData.username);
27+
await this.page.fill(this.loginPageObjects.PASSWORD_EDITBOX_XPATH, decipherPassword);
28+
await this.page.click(this.loginPageObjects.LOGIN_BUTTON_XPATH);
29+
}
30+
31+
32+
33+
}

playwright.config.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ module.exports = {
2121
channel: `chrome`,
2222

2323
//Browser Mode
24-
headless: `true`,
24+
headless: false,
2525

2626
//Slows down execution by ms
2727
slowMo: 0,
2828

2929
//Browser height and width
3030
viewport: { width: 1500, height: 730 },
31-
ignoreHTTPSErrors: `true`,
31+
ignoreHTTPSErrors: true,
3232

3333
//Enable File Downloads in Chrome
34-
acceptDownloads: `true`,
34+
acceptDownloads: true,
3535

3636
//Artifacts
3737
screenshot: `only-on-failure`,
@@ -43,11 +43,11 @@ module.exports = {
4343
name: `Chromium`,
4444
use: {
4545
browserName: `chromium`,
46-
headless: `true`,
46+
headless: true,
4747
slowMo: 0,
4848
viewport: { width: 1500, height: 730 },
49-
ignoreHTTPSErrors: `true`,
50-
acceptDownloads: `true`,
49+
ignoreHTTPSErrors: true,
50+
acceptDownloads: true,
5151
screenshot: `only-on-failure`,
5252
video: `retain-on-failure`,
5353
trace: `retain-on-failure`,
@@ -58,11 +58,11 @@ module.exports = {
5858
name: `Firefox`,
5959
use: {
6060
browserName: `firefox`,
61-
headless: `true`,
61+
headless: true,
6262
slowMo: 0,
6363
viewport: { width: 1500, height: 730 },
64-
ignoreHTTPSErrors: `true`,
65-
acceptDownloads: `true`,
64+
ignoreHTTPSErrors: true,
65+
acceptDownloads: true,
6666
screenshot: `only-on-failure`,
6767
video: `retain-on-failure`,
6868
trace: `retain-on-failure`,
@@ -74,11 +74,11 @@ module.exports = {
7474
use: {
7575
browserName: `chromium`,
7676
channel: `msedge`,
77-
headless: `true`,
77+
headless: false,
7878
slowMo: 0,
7979
viewport: { width: 1500, height: 730 },
80-
ignoreHTTPSErrors: `true`,
81-
acceptDownloads: `true`,
80+
ignoreHTTPSErrors: true,
81+
acceptDownloads: true,
8282
screenshot: `only-on-failure`,
8383
video: `retain-on-failure`,
8484
trace: `retain-on-failure`,
@@ -88,11 +88,11 @@ module.exports = {
8888
name: `WebKit`,
8989
use: {
9090
browserName: `webkit`,
91-
headless: `true`,
91+
headless: true,
9292
slowMo: 0,
9393
viewport: { width: 1500, height: 730 },
94-
ignoreHTTPSErrors: `true`,
95-
acceptDownloads: `true`,
94+
ignoreHTTPSErrors: true,
95+
acceptDownloads: true,
9696
screenshot: `only-on-failure`,
9797
video: `retain-on-failure`,
9898
trace: `retain-on-failure`,
@@ -103,10 +103,10 @@ module.exports = {
103103
use: {
104104
...devices[`iPhone 12 Pro Max`],
105105
browserName: `chromium`,
106-
headless: `true`,
106+
headless: true,
107107
slowMo: 0,
108-
ignoreHTTPSErrors: `true`,
109-
acceptDownloads: `true`,
108+
ignoreHTTPSErrors: true,
109+
acceptDownloads: true,
110110
screenshot: `only-on-failure`,
111111
video: `retain-on-failure`,
112112
trace: `retain-on-failure`,

testData.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"waitForElement": 300000,
3-
"URL": "https://www.google.com",
4-
"username": "admin",
5-
"password": "password",
3+
"URL": "https://phptravels.org/index.php?rp=/login",
4+
"username": "user@phptravels.com",
5+
"password": "U2FsdGVkX1+viC6x/NN+BmiAKY0bSWljucVMQedC6d0=",
66
"dbUsername": "",
77
"dbPassword": "",
88
"dbServerName": "",

tests/api/POST.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test(`@API postUsers`, async () => {
1414

1515
const responseBodyParams = (await apiActions.readValuesFromTextFile(`postUsers`)).split(`#`)[1];
1616
await apiActions.verifyResponseBody(responseBodyParams, response.body, expect.getState().currentTestName, `Respomse Body`);
17-
// console.log(JSON.stringify(response.headers).trim());
17+
1818
const responseBodyHeaders = (await apiActions.readValuesFromTextFile(`postUsers`)).split(`#`)[2];
1919
await apiActions.verifyResponseBody(responseBodyHeaders, response.headers, expect.getState().currentTestName, `Respomse Headers`);
2020
});

tests/functional/Login.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import test from '../../lib/BasePages';
2+
3+
test(`Login to PHP travels.`, async ({ loginPage }) => {
4+
await loginPage.navigateToURL();
5+
await loginPage.loginToApplication();
6+
});

0 commit comments

Comments
 (0)