Skip to content

Commit cfeeaff

Browse files
committed
Documentation is Updated
1 parent e4fb842 commit cfeeaff

File tree

11 files changed

+256
-9
lines changed

11 files changed

+256
-9
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ This is a robust end-to-end Test Automation Framework built using **Playwright**
55

66
---
77

8+
## 📚 Documentation
9+
10+
- [BasePage](docs/BasePage.md)
11+
- [LoginPage](docs/LoginPage.md)
12+
- [HomePage](docs/HomePage.md)
13+
- [Logger Utility](docs/logger.md)
14+
- [Allure Helper](docs/allureHelper.md)
15+
- [Playwright Config](docs/playwright-config.md)
16+
817
## 🚀 Features
918

1019
- ✅ TypeScript-based Playwright tests

docs/AllureHelper.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Allure Helper
2+
3+
**File:** `utils/allureHelper.ts`
4+
5+
## Purpose
6+
7+
Simplifies Allure reporting integration.
8+
Allows marking steps with status and stopping tests on failure.
9+
10+
---
11+
12+
## Key Method
13+
14+
### stepCheck
15+
16+
```typescript
17+
stepCheck(message: string, status: string = 'passed', shouldStop: boolean = false)
18+
```
19+
- Logs and reports a step.
20+
- Optionally fails the test if `shouldStop` is true.
21+
22+
---
23+
24+
## Usage Example
25+
26+
```typescript
27+
await AllureHelper.stepCheck('Login is successful');
28+
```

docs/BasePage.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# BasePage Class
2+
3+
**File:** `pages/BasePage.ts`
4+
5+
## Purpose
6+
7+
The `BasePage` class provides reusable, robust, and well-logged utility methods for interacting with web elements in Playwright.
8+
All specific page classes should extend `BasePage` to inherit these utilities, ensuring consistency and reducing code duplication.
9+
10+
---
11+
12+
## Methods
13+
14+
### waitForElement
15+
16+
```typescript
17+
async waitForElement(
18+
locator: Locator,
19+
timeout: number = 5000,
20+
maxRetries: number = 3,
21+
delayBetweenRetries: number = 1000
22+
): Promise<void>
23+
```
24+
Waits for an element to appear/become ready, with configurable retries and delays.
25+
- Retries up to `maxRetries` times, waiting `timeout` ms each time.
26+
- Logs each attempt and failure.
27+
- Throws an error if the element is not found after all retries.
28+
29+
---
30+
31+
### clickElement
32+
33+
```typescript
34+
async clickElement(locator: Locator, wait: boolean = true): Promise<void>
35+
```
36+
Clicks an element, optionally waiting for it to be ready first.
37+
38+
---
39+
40+
### enterText
41+
42+
```typescript
43+
async enterText(locator: Locator, value: string, wait: boolean = true): Promise<void>
44+
```
45+
Fills an input field with the provided value, optionally waiting for readiness.
46+
47+
---
48+
49+
### typeText
50+
51+
```typescript
52+
async typeText(locator: Locator, value: string, wait: boolean = true): Promise<void>
53+
```
54+
Types text into an input field character by character, simulating real user input.
55+
56+
---
57+
58+
### selectDropdown
59+
60+
```typescript
61+
async selectDropdown(locator: Locator, value: string, wait: boolean = true): Promise<void>
62+
```
63+
Selects an option from a dropdown by value.
64+
65+
---
66+
67+
### getElementText
68+
69+
```typescript
70+
async getElementText(locator: Locator, wait: boolean = true): Promise<string>
71+
```
72+
Retrieves the text content of an element.
73+
74+
---
75+
76+
### isElementVisible
77+
78+
```typescript
79+
async isElementVisible(locator: Locator): Promise<boolean>
80+
```
81+
Checks if an element is visible on the page.
82+
83+
---
84+
85+
## Logging
86+
87+
All actions are logged using the shared logger utility for traceability and easier debugging.
88+
89+
---
90+
91+
## Usage Example
92+
93+
```typescript
94+
import { BasePage } from './BasePage';
95+
96+
class LoginPage extends BasePage {
97+
// Define locators and page-specific methods here
98+
}
99+
```
100+
101+
---
102+
103+
## Maintenance Tips
104+
105+
- Add new generic element actions here so all pages benefit.
106+
- Avoid page-specific logic in `BasePage`.
107+
- Use logs to diagnose flaky tests or UI issues

docs/HomePage.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# HomePage Class
2+
3+
**File:** `pages/HomePage.ts`
4+
5+
## Purpose
6+
7+
Encapsulates actions and verifications for the home page after login.
8+
9+
---
10+
11+
## Typical Methods
12+
13+
- `verifyLoginIsSuccessful()`: Checks if login succeeded by verifying the URL or a specific element.
14+
- `verifyProductExists(productName: string)`: Checks if a product is visible on the home page.
15+
16+
---
17+
18+
## Usage Example
19+
20+
```typescript
21+
const homePage = new HomePage(page);
22+
await homePage.verifyLoginIsSuccessful();
23+
```
24+
25+
---
26+
27+
## Maintenance Tips
28+
29+
- Add new methods for home page actions or verifications as needed.

docs/Logger.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logger Utility
2+
3+
**File:** `utils/logger.ts`
4+
5+
## Purpose
6+
7+
Provides centralized logging using Winston.
8+
Logs to both console and file for traceability.
9+
10+
---
11+
12+
## Usage Example
13+
14+
```typescript
15+
logger.info('This is an info message');
16+
logger.error('This is an error message');
17+
```
18+
19+
---
20+
21+
## Maintenance Tips
22+
23+
- Adjust log levels or formats as needed.
24+
- Ensure logs are rotated or archived in CI environments.

docs/LoginPage.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# LoginPage Class
2+
3+
**File:** `pages/LoginPage.ts`
4+
5+
## Purpose
6+
7+
Encapsulates all selectors and actions for the login page.
8+
Provides a single place to maintain login logic, making tests more readable and maintainable.
9+
10+
---
11+
12+
## Typical Methods
13+
14+
- `goto()`: Navigates to the login page URL.
15+
- `login(userName: string, password: string)`: Fills in the username and password fields and clicks the login button.
16+
17+
---
18+
19+
## Usage Example
20+
21+
```typescript
22+
const loginPage = new LoginPage(page);
23+
await loginPage.goto();
24+
await loginPage.login('user', 'pass');
25+
```
26+
27+
---
28+
29+
## Maintenance Tips
30+
31+
- Update selectors here if the login page UI changes.
32+
- Add new login-related actions as needed.

docs/PlaywrightConfiguration.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Playwright Configuration
2+
3+
**File:** `playwright.config.ts`
4+
5+
## Purpose
6+
7+
Centralizes all Playwright test settings:
8+
- Test directory
9+
- Retries
10+
- Timeouts
11+
- Reporters
12+
- Browser/project settings
13+
14+
---
15+
16+
## Maintenance Tips
17+
18+
- Update browser/project settings as needed.
19+
- Adjust timeouts and retries for stability.

pages/BasePage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export class BasePage {
4040

4141
async enterText(locator: Locator, value: string, wait: boolean = true): Promise<void> {
4242
if (wait) await this.waitForElement(locator);
43-
await locator.fill(value);
43+
const response = await locator.fill(value);
44+
4445
logger.info(`Filled input ${locator.toString()} with value: ${value}`);
4546
}
4647

pages/HomePage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export class HomePage extends BasePage{
77
protected readonly page: Page;
88

99
private txtProductLink(productName: string) :Locator {
10-
return this.page.locator(`text="${productName}"`)
10+
return this.page.locator(`text="${productName}"`);
11+
1112
}
1213

1314

pages/LoginPage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ export class LoginPage extends BasePage {
88

99

1010
private get txtUserName(): Locator {
11-
return this.page.locator('#user-name');
11+
return this.page.getByRole('textbox', {name : 'Username'});
1212
}
1313

1414
private get txtPassword(): Locator {
15-
return this.page.locator('#password');
15+
return this.page.getByRole('textbox', {name:'Password'});
1616
}
1717

1818
private get btnLogin() : Locator {
19-
return this.page.locator('#login-button');
19+
return this.page.getByRole('button',{name : 'Login'});
2020
}
2121

2222
async goto() {
@@ -29,7 +29,7 @@ export class LoginPage extends BasePage {
2929
}
3030

3131
async login(userName: string, password: string) {
32-
await this.enterText(this.txtUserName, userName);
32+
const response = await this.enterText(this.txtUserName, userName);
3333
await this.enterText(this.txtPassword, password);
3434
await this.clickElement(this.btnLogin);
3535
}

0 commit comments

Comments
 (0)