Skip to content

Commit 9953719

Browse files
Added RecoverPasswordPage and Script
1 parent fea93d4 commit 9953719

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

pages/RecoverPasswordPage.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class RecoverPasswordPage {
2+
constructor(page) {
3+
this.page = page;
4+
this.emailInput = page.locator('#email');
5+
this.recoverpasswordButton = page.locator('[class*="btn btn-primary"]');
6+
this.successMessage = page.locator('#message');
7+
this.errorMessage = page.locator('#errorMessage');
8+
}
9+
10+
async navigate() {
11+
await this.page.goto('https://qa-practice.netlify.app/recover-password');
12+
}
13+
14+
15+
async submitdata() {
16+
await this.recoverpasswordButton.click();
17+
}
18+
}
19+
20+
module.exports = RecoverPasswordPage;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const { test, expect } = require('@playwright/test');
2+
const RecoverPasswordPage = require('../../pages/RecoverPasswordPage');
3+
4+
test.describe('Recover Password with user data', () => {
5+
let recoverPassword;
6+
7+
test.beforeEach(async ({ page }) => {
8+
// Initialize the Recover Password Page object
9+
recoverPassword = new RecoverPasswordPage(page);
10+
11+
// Navigate to the Recover Password page
12+
await recoverPassword.navigate();
13+
});
14+
15+
test('should require mandatory fields (empty form)', async () => {
16+
// Submit the form without filling any fields
17+
await recoverPassword.submitdata();
18+
19+
// Validate error message for empty fields
20+
const validationMessage = await recoverPassword.emailInput.evaluate(input => input.validationMessage);
21+
//expect(validationMessage).toBe('Please fill out this field.');
22+
const browserName = test.info().project.name;
23+
24+
// Browser-specific validation message check
25+
if (browserName === 'chromium' || browserName === 'firefox') {
26+
expect(validationMessage).toBe('Please fill out this field.');
27+
} else if (browserName === 'webkit') {
28+
expect(validationMessage).toBe('Fill out this field');
29+
}
30+
});
31+
32+
test('should successfully recover password with entered data', async () => {
33+
//user to enter email
34+
const email = 'test@gmail.com';
35+
36+
// Fill the email field with the entered data
37+
await recoverPassword.emailInput.fill(email);
38+
39+
// Submit the form
40+
await recoverPassword.submitdata();
41+
42+
// Validate success message
43+
await expect(recoverPassword.successMessage).toBeVisible();
44+
await expect(recoverPassword.successMessage).toHaveText(
45+
`An email with the new password has been sent to ${email}. Please verify your inbox!`
46+
);
47+
});
48+
});

0 commit comments

Comments
 (0)