Skip to content

Commit 5f821a6

Browse files
Merge pull request #17 from py-dev-nandini-12/test-new-e2e
Test new e2e
2 parents 5e9d8bf + 458a4f7 commit 5f821a6

File tree

3 files changed

+51
-38
lines changed

3 files changed

+51
-38
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ yarn-error.log*
4040
*.tsbuildinfo
4141
next-env.d.ts
4242

43-
tests/reports
43+
tests/reports
44+
playwright-report

playwright.config.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import { defineConfig } from '@playwright/test';
1+
import { defineConfig } from "@playwright/test";
22

33
export default defineConfig({
44
webServer: {
5-
command: 'npm run dev',
5+
command: "npm run dev",
66
port: 3000,
77
reuseExistingServer: true,
88
},
9-
reporter: [
10-
['list'],
11-
['html', { outputFolder: 'playwright-report' }]
12-
],
9+
workers: 4, // Specify the number of workers
10+
reporter: [["list"], ["html", { outputFolder: "playwright-report" }]],
1311
});

tests/form.spec.ts

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,3 @@
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-
321
import { test, expect } from "@playwright/test";
332

343
test.describe("Form Submission Tests", () => {
@@ -95,3 +64,48 @@ test.describe("Form Submission Tests", () => {
9564
await expect(page.locator('input[name="email"]')).toHaveValue("");
9665
});
9766
});
67+
68+
test.describe("Weather Widget", () => {
69+
test("should display current weather", async ({ page, context }) => {
70+
// Mock geolocation to return a fixed location
71+
await context.grantPermissions(["geolocation"]);
72+
await context.setGeolocation({ latitude: 40.7128, longitude: -74.006 });
73+
74+
await page.goto("/form");
75+
76+
// Wait for the weather widget to load
77+
await page.waitForSelector("text=Current Weather", { timeout: 3000 });
78+
79+
// Check if temperature and wind speed are displayed
80+
const temperatureText = await page
81+
.locator("text=Temperature:")
82+
.last()
83+
.textContent();
84+
const windSpeedText = await page
85+
.locator("text=Wind Speed:")
86+
.last()
87+
.textContent();
88+
89+
expect(temperatureText).toMatch(/Temperature: \d+\.\d+°C/);
90+
expect(windSpeedText).toMatch(/Wind Speed: \d+\.\d+ km\/h/);
91+
});
92+
});
93+
94+
test.describe("Task List", () => {
95+
test("should allow adding and deleting tasks", async ({ page }) => {
96+
await page.goto("/");
97+
98+
// Add a new task
99+
await page.fill('input[placeholder="Add a new task"]', "Test Task");
100+
await page.click("text=Add Task");
101+
102+
// Verify the task is added
103+
await expect(page.locator("text=Test Task")).toBeVisible();
104+
105+
// Delete the task
106+
await page.click("text=Delete");
107+
108+
// Verify the task is removed
109+
await expect(page.locator("text=Test Task")).not.toBeVisible();
110+
});
111+
});

0 commit comments

Comments
 (0)