Skip to content

Commit a70c20b

Browse files
committed
Home Page is added and updated existing test with assertions
1 parent acf784b commit a70c20b

File tree

6 files changed

+75
-13
lines changed

6 files changed

+75
-13
lines changed

pages/BasePage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export class BasePage {
6565

6666
async isElementVisible(locator: Locator): Promise<boolean> {
6767
try {
68+
logger.info(`Verifying the visibility of locator: ${locator.toString()}`);
6869
return await locator.isVisible();
6970
} catch {
7071
return false;

pages/HomePage.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Page, Locator } from '@playwright/test'
2+
import { BasePage } from '../pages/BasePage'
3+
import { AllureHelper } from '../utils/allureHelper'
4+
5+
export class HomePage extends BasePage{
6+
7+
protected readonly page: Page;
8+
9+
private txtProductLink(productName: string) :Locator {
10+
return this.page.locator(`text="${productName}"`)
11+
}
12+
13+
14+
constructor(page: Page) {
15+
super();
16+
this.page = page;
17+
}
18+
19+
async verifyLoginIsSuccessful() {
20+
const currentUrl = this.page.url();
21+
if(currentUrl.includes('inventory')) {
22+
AllureHelper.stepCheck("Login is Successful")
23+
} else {
24+
AllureHelper.stepCheck("Login is unsuccssful", 'failed', true)
25+
}
26+
27+
}
28+
29+
async verifyProductExists(productName: string) {
30+
const isAvailable = await this.isElementVisible(this.txtProductLink(`${productName}`));
31+
if (isAvailable) {
32+
AllureHelper.stepCheck("Product With the Name Exists")
33+
} else {
34+
AllureHelper.stepCheck("Product with the Name Does not Exist", 'failed', true)
35+
}
36+
}
37+
38+
}

pages/LoginPage.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,10 @@ export class LoginPage extends BasePage {
2828
this.page = page;
2929
}
3030

31-
async login(username: string, password: string) {
32-
await this.txtUserName.fill(username);
33-
await this.txtPassword.fill(password);
34-
const enabled = await this.btnLogin.isEnabled();
35-
if (enabled){
36-
await AllureHelper.stepCheck(`Login Button is Enabled`);
37-
} else {
38-
await AllureHelper.stepCheck('Login Button is not Enabled', 'passed', true)
39-
}
40-
await this.btnLogin.click();
31+
async login(userName: string, password: string) {
32+
await this.enterText(this.txtUserName, userName);
33+
await this.enterText(this.txtPassword, password);
34+
await this.clickElement(this.btnLogin);
4135
}
4236

4337

playwright.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { defineConfig } from '@playwright/test';
22

33
export default defineConfig({
44
testDir: './tests',
5+
workers: 2,
56
retries: 1,
67
timeout: 30000,
78
reporter: [['list'],['allure-playwright'],['html', { open: 'never' }]],

tests/ui/login.spec.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
import { test, expect } from '../setup';
22
import { LoginPage } from '../../pages/LoginPage'
3+
import { HomePage } from '../../pages/HomePage'
34

45

5-
test.describe('@smoke', () => {
6+
test.describe.parallel('@smoke', () => {
7+
68
test('Valid Login 1', async ({ page }) => {
79
const loginPage = new LoginPage(page);
10+
const homePage = new HomePage(page);
811
await loginPage.goto();
9-
await loginPage.login("standard_user", "secret_sauce")
12+
await loginPage.login("standard_user", "secret_sauce");
13+
await homePage.verifyLoginIsSuccessful();
14+
15+
1016
});
1117

1218
test('Valid Login 2', async ({ page }) => {
1319
const loginPage = new LoginPage(page);
20+
const homePage = new HomePage(page);
1421
await loginPage.goto();
15-
await loginPage.login("standard_user", "secret_sauce")
22+
await loginPage.login("standard_user", "secret_sauce");
23+
await homePage.verifyProductExists("Sauce Labs Backpack");
24+
1625
});
1726

1827
})

utils/allureHelper.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { allure } from 'allure-playwright';
2+
import { logger } from './logger';
3+
4+
type AllureStatus = 'passed' | 'failed' | 'broken' | 'skipped' | 'info' | 'warning';
5+
6+
export class AllureHelper {
7+
static async stepCheck(
8+
message: string,
9+
status: AllureStatus = 'info',
10+
shouldStop = false
11+
): Promise<void> {
12+
await allure.step(`[${status.toUpperCase()}] ${message}`, async () => {
13+
logger.info(`[${status.toUpperCase()}] ${message}`);
14+
if (['failed', 'broken'].includes(status) && shouldStop) {
15+
throw new Error(`❌ Test stopped: ${message}`);
16+
}
17+
});
18+
}
19+
}

0 commit comments

Comments
 (0)