|
29 | 29 | // await expect(page.locator('p')).toHaveText('Submission failed. Please try again.'); |
30 | 30 | // }); |
31 | 31 |
|
32 | | -import { test, expect } from '@playwright/test'; |
| 32 | +import { test, expect } from "@playwright/test"; |
33 | 33 |
|
34 | | -test.describe('Form Submission Tests', () => { |
35 | | - test('✅ Form submission works correctly', async ({ page }) => { |
36 | | - await page.goto('/form'); |
| 34 | +test.describe("Form Submission Tests", () => { |
| 35 | + test("✅ Form submission works correctly", async ({ page }) => { |
| 36 | + await page.goto("/form"); |
37 | 37 |
|
38 | 38 | // Check form elements exist |
39 | 39 | await expect(page.locator('input[name="name"]')).toBeVisible(); |
40 | 40 | await expect(page.locator('input[name="email"]')).toBeVisible(); |
41 | | - await expect(page.locator('button[type="submit"]')).toHaveText('Submit'); |
| 41 | + await expect(page.locator('button[type="submit"]')).toHaveText("Submit"); |
42 | 42 |
|
43 | 43 | // Fill out the form |
44 | | - await page.fill('input[name="name"]', 'John Doe'); |
45 | | - await page.fill('input[name="email"]', '[email protected]'); |
| 44 | + await page.fill('input[name="name"]', "John Doe"); |
| 45 | + await page.fill('input[name="email"]', "[email protected]"); |
46 | 46 |
|
47 | 47 | // Submit the form |
48 | 48 | await page.click('button[type="submit"]'); |
49 | 49 |
|
50 | 50 | // Expect success message |
51 | | - await expect(page.locator('#message')).toHaveText(`Hello John Doe, your form has been submitted successfully!`); |
| 51 | + await expect(page.locator("#message")).toHaveText( |
| 52 | + `Hello John Doe, your form has been submitted successfully!` |
| 53 | + ); |
52 | 54 | }); |
53 | 55 |
|
54 | | - test('❌ Shows validation error if fields are missing', async ({ page }) => { |
55 | | - await page.goto('/form'); |
| 56 | + test("❌ Shows validation error if fields are missing", async ({ page }) => { |
| 57 | + await page.goto("/form"); |
56 | 58 |
|
57 | 59 | // Click submit without filling anything |
58 | 60 | await page.click('button[type="submit"]'); |
59 | 61 |
|
60 | 62 | // Expect validation error |
61 | | - await expect(page.locator('#error')).toHaveText('Both Name and Email are required'); |
| 63 | + await expect(page.locator("#error")).toHaveText( |
| 64 | + "Both Name and Email are required" |
| 65 | + ); |
62 | 66 | }); |
63 | 67 |
|
64 | | - test('❌ Shows validation error for invalid email', async ({ page }) => { |
65 | | - await page.goto('/form'); |
| 68 | + test("❌ Shows validation error for invalid email", async ({ page }) => { |
| 69 | + await page.goto("/form"); |
66 | 70 |
|
67 | 71 | // Fill in the name field |
68 | | - await page.fill('input[name="name"]', 'John Doe'); |
| 72 | + await page.fill('input[name="name"]', "John Doe"); |
69 | 73 | // Enter an invalid email |
70 | | - await page.fill('input[name="email"]', 'invalid-email'); |
| 74 | + await page.fill('input[name="email"]', "invalid-email"); |
71 | 75 |
|
72 | 76 | // Submit the form |
73 | 77 | await page.click('button[type="submit"]'); |
74 | 78 |
|
75 | 79 | // Expect email validation error |
76 | | - await expect(page.locator('#error')).toHaveText('Invalid email format'); |
| 80 | + await expect(page.locator("#error")).toHaveText("Invalid email formats"); |
77 | 81 | }); |
78 | 82 |
|
79 | | - test('🔄 Reset button clears the form', async ({ page }) => { |
80 | | - await page.goto('/form'); |
| 83 | + test("🔄 Reset button clears the form", async ({ page }) => { |
| 84 | + await page.goto("/form"); |
81 | 85 |
|
82 | 86 | // Fill out the form |
83 | | - await page.fill('input[name="name"]', 'John Doe'); |
84 | | - await page.fill('input[name="email"]', '[email protected]'); |
| 87 | + await page.fill('input[name="name"]', "John Doe"); |
| 88 | + await page.fill('input[name="email"]', "[email protected]"); |
85 | 89 |
|
86 | 90 | // Click reset |
87 | 91 | await page.click('button[type="button"]'); |
88 | 92 |
|
89 | 93 | // Expect fields to be cleared |
90 | | - await expect(page.locator('input[name="name"]')).toHaveValue(''); |
91 | | - await expect(page.locator('input[name="email"]')).toHaveValue(''); |
| 94 | + await expect(page.locator('input[name="name"]')).toHaveValue(""); |
| 95 | + await expect(page.locator('input[name="email"]')).toHaveValue(""); |
92 | 96 | }); |
93 | 97 | }); |
0 commit comments