|
| 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