1- // import { test, expect } from '@playwright/test';
2-
3- // test('Form submission works correctly', async ({ page }) => {
4- // await page.goto('/form');
5-
6- // // Ensure form elements are present
7- // await expect(page.locator('input[placeholder="Enter your name"]')).toBeVisible();
8- // await expect(page.locator('input[placeholder="Enter your email"]')).toBeVisible();
9- // await expect(page.locator('button[type="submit"]')).toHaveText('Submit');
10-
11- // // Fill out the form
12- // await page.fill('input[placeholder="Enter your name"]', 'John Doe');
13- // await page.fill('input[placeholder="Enter your email"]', '[email protected] '); 14-
15- // // Submit the form
16- // await page.click('button[type="submit"]');
17-
18- // // Wait for success message
19- // await expect(page.locator('p')).toHaveText('Thank you, John Doe!');
20- // });
21-
22- // test('Shows validation error if fields are missing', async ({ page }) => {
23- // await page.goto('/form');
24-
25- // // Try to submit without filling anything
26- // await page.click('button[type="submit"]');
27-
28- // // Expect an error message
29- // await expect(page.locator('p')).toHaveText('Submission failed. Please try again.');
30- // });
31-
321import { test , expect } from '@playwright/test' ;
332
343test . describe ( 'Form Submission Tests' , ( ) => {
@@ -44,11 +13,8 @@ test.describe('Form Submission Tests', () => {
4413 await page . fill ( 'input[name="name"]' , 'John Doe' ) ;
4514 await page . fill ( 'input[name="email"]' , '[email protected] ' ) ; 4615
47- // Submit the form
48- await page . click ( 'button[type="submit"]' ) ;
49-
50- // Expect success message
51- await expect ( page . locator ( '#message' ) ) . toHaveText ( `Hello John Doe, your form has been submitted successfully!` ) ;
16+ // Intentionally fail this expectation
17+ await expect ( page . locator ( '#message' ) ) . toHaveText ( `This message does not exist` ) ;
5218 } ) ;
5319
5420 test ( '❌ Shows validation error if fields are missing' , async ( { page } ) => {
@@ -91,3 +57,5 @@ test.describe('Form Submission Tests', () => {
9157 await expect ( page . locator ( 'input[name="email"]' ) ) . toHaveValue ( '' ) ;
9258 } ) ;
9359} ) ;
60+
61+
0 commit comments