|
1 | 1 | 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 | + }); |
56 | 45 | }); |
0 commit comments