Skip to content

Commit 68d1698

Browse files
Added POM structure script
1 parent 72e9eb0 commit 68d1698

File tree

3 files changed

+69
-56
lines changed

3 files changed

+69
-56
lines changed

pages/LoginPage.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class LoginPage {
2+
constructor(page) {
3+
this.page = page;
4+
this.emailInput = page.locator('#email');
5+
this.passwordInput = page.locator('#password');
6+
this.submitButton = page.getByRole('button', { name: 'Submit' });
7+
//this.errorMessage = page.getByText('Bad credentials! Please try');
8+
}
9+
10+
async navigate() {
11+
await this.page.goto('https://qa-practice.netlify.app/auth_ecommerce');
12+
}
13+
14+
async login(email, password) {
15+
await this.emailInput.fill(email);
16+
await this.passwordInput.fill(password);
17+
await this.submitButton.click();
18+
}
19+
20+
async getErrorMessage() {
21+
return this.page.getByText("Bad credentials! Please try again! Make sure that you've registered.");
22+
}
23+
}
24+
module.exports = LoginPage;

playwright.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const { defineConfig, devices } = require('@playwright/test');
77
*/
88
// require('dotenv').config({ path: path.resolve(__dirname, '.env') });
99

10-
/**
10+
/**SS
1111
* @see https://playwright.dev/docs/test-configuration
1212
*/
1313
module.exports = defineConfig({
14-
testDir: './tests',
14+
testDir: './tests/Forms',
1515
/* Run tests in files in parallel */
1616
fullyParallel: true,
1717
/* Fail the build on CI if you accidentally left test.only in the source code. */

tests/Forms/Login.spec.js

Lines changed: 43 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,45 @@
11
const { test, expect } = require('@playwright/test');
2-
3-
// Verify the page title
4-
test('Verify page title: QA Practice | Learn with RV', async ({ page }) => {
5-
await page.goto('https://qa-practice.netlify.app/auth_ecommerce');
6-
7-
// Verify that the page title matches the expected value
8-
await expect(page).toHaveTitle('QA Practice | Learn with RV');
9-
});
10-
11-
// Test form submission without entering any fields
12-
test('Verify form validation for empty fields', async ({ page }) => {
13-
await page.goto('https://qa-practice.netlify.app/auth_ecommerce');
14-
15-
// Attempt to submit the form without filling in the fields
16-
await page.getByRole('button', { name: 'Submit' }).click();
17-
18-
// Check if the error message is displayed
19-
const errorMessage = page.getByText('Bad credentials! Please try');
20-
await expect(errorMessage).toBeVisible();
21-
await expect(errorMessage).toHaveText(
22-
"Bad credentials! Please try again! Make sure that you've registered."
23-
);
24-
});
25-
26-
// Validate the form with invalid credentials
27-
test('Verify form validation for invalid credentials', async ({ page }) => {
28-
await page.goto('https://qa-practice.netlify.app/auth_ecommerce');
29-
30-
// Fill the form with invalid email and password
31-
await page.locator('#email').fill('test@gmail.com');
32-
await page.locator('#password').fill('test@123');
33-
await page.getByRole('button', { name: 'Submit' }).click();
34-
35-
// Check if the error message is displayed
36-
const errorMessage = page.getByText('Bad credentials! Please try');
37-
await expect(errorMessage).toBeVisible();
38-
await expect(errorMessage).toHaveText(
39-
"Bad credentials! Please try again! Make sure that you've registered."
40-
);
41-
});
42-
43-
// Validate login functionality with valid credentials
44-
test('Verify login with valid credentials', async ({ page }) => {
45-
await page.goto('https://qa-practice.netlify.app/auth_ecommerce');
46-
47-
// Fill the form with valid email and password
48-
await page.locator('#email').fill('admin@admin.com');
49-
await page.locator('#password').fill('admin123');
50-
await page.getByRole('button', { name: 'Submit' }).click();
51-
52-
// Verify the presence of the shopping cart page
53-
const shoppingCart = page.locator('text=SHOPPING CART');
54-
await expect(shoppingCart).toBeVisible();
55-
await expect(shoppingCart).toHaveText('SHOPPING CART');
2+
const LoginPage = require('../../pages/LoginPage');
3+
4+
test.describe('Login Page Tests', () => {
5+
let loginPage;
6+
7+
test.beforeEach(async ({ page }) => {
8+
loginPage = new LoginPage(page);
9+
await loginPage.navigate();
10+
});
11+
12+
test('Verify page title', async () => {
13+
await expect(loginPage.page).toHaveTitle('QA Practice | Learn with RV');
14+
});
15+
16+
test('Validate email field for invalid format', async ({ page }) => {
17+
await loginPage.emailInput.fill('invalidemail'); // No '@' or domain
18+
await loginPage.submitButton.click();
19+
const validationMessage = await loginPage.emailInput.evaluate(input => input.validationMessage);
20+
const browserName = test.info().project.name;
21+
22+
// Browser-specific validation message check
23+
if (browserName === 'chromium') {
24+
expect(validationMessage).toBe("Please include an '@' in the email address. 'invalidemail' is missing an '@'.");
25+
} else if (browserName === 'firefox') {
26+
expect(validationMessage).toBe("Please enter an email address.");
27+
} else if (browserName === 'webkit') {
28+
expect(validationMessage).toBe("Enter an email address");
29+
}
30+
});
31+
32+
test('Validate login with invalid credentials', async () => {
33+
await loginPage.login('test@gmail.com', 'wrongpassword');
34+
const errorMessage = await loginPage.getErrorMessage();
35+
await expect(errorMessage).toBeVisible();
36+
await expect(errorMessage).toHaveText("Bad credentials! Please try again! Make sure that you've registered.");
37+
});
38+
39+
test('Validate login with valid credentials', async () => {
40+
await loginPage.login('admin@admin.com', 'admin123');
41+
const shoppingCart = await loginPage.page.locator('text=SHOPPING CART');
42+
await expect(shoppingCart).toBeVisible();
43+
await expect(shoppingCart).toHaveText("SHOPPING CART");
44+
});
5645
});

0 commit comments

Comments
 (0)