From 768b7633b8fa77ffc7545e970907a0419f14603a Mon Sep 17 00:00:00 2001 From: Nandini Chatterjee Date: Wed, 30 Apr 2025 14:53:05 +0100 Subject: [PATCH 1/4] feat: implement form submission tests and add weather widget and task list tests --- tests/form.spec.ts | 66 ++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/tests/form.spec.ts b/tests/form.spec.ts index 3da3458..f448aef 100644 --- a/tests/form.spec.ts +++ b/tests/form.spec.ts @@ -1,34 +1,3 @@ -// import { test, expect } from '@playwright/test'; - -// test('Form submission works correctly', async ({ page }) => { -// await page.goto('/form'); - -// // Ensure form elements are present -// await expect(page.locator('input[placeholder="Enter your name"]')).toBeVisible(); -// await expect(page.locator('input[placeholder="Enter your email"]')).toBeVisible(); -// await expect(page.locator('button[type="submit"]')).toHaveText('Submit'); - -// // Fill out the form -// await page.fill('input[placeholder="Enter your name"]', 'John Doe'); -// await page.fill('input[placeholder="Enter your email"]', 'john@example.com'); - -// // Submit the form -// await page.click('button[type="submit"]'); - -// // Wait for success message -// await expect(page.locator('p')).toHaveText('Thank you, John Doe!'); -// }); - -// test('Shows validation error if fields are missing', async ({ page }) => { -// await page.goto('/form'); - -// // Try to submit without filling anything -// await page.click('button[type="submit"]'); - -// // Expect an error message -// await expect(page.locator('p')).toHaveText('Submission failed. Please try again.'); -// }); - import { test, expect } from "@playwright/test"; test.describe("Form Submission Tests", () => { @@ -95,3 +64,38 @@ test.describe("Form Submission Tests", () => { await expect(page.locator('input[name="email"]')).toHaveValue(""); }); }); + +test.describe("Weather Widget", () => { + test("should display current weather", async ({ page }) => { + await page.goto("/form"); + + // Wait for the weather widget to load + await page.waitForSelector("text=Current Weather"); + + // Check if temperature and wind speed are displayed + const temperature = await page.locator("text=Temperature:").isVisible(); + const windSpeed = await page.locator("text=Wind Speed:").isVisible(); + + expect(temperature).toBeTruthy(); + expect(windSpeed).toBeTruthy(); + }); +}); + +test.describe("Task List", () => { + test("should allow adding and deleting tasks", async ({ page }) => { + await page.goto("/"); + + // Add a new task + await page.fill('input[placeholder="Add a new task"]', "Test Task"); + await page.click("text=Add Task"); + + // Verify the task is added + await expect(page.locator("text=Test Task")).toBeVisible(); + + // Delete the task + await page.click("text=Delete"); + + // Verify the task is removed + await expect(page.locator("text=Test Task")).not.toBeVisible(); + }); +}); From 20b9fd16142c5aa7fe387d9aa1b0c5aaa4974905 Mon Sep 17 00:00:00 2001 From: Nandini Chatterjee Date: Wed, 30 Apr 2025 15:00:55 +0100 Subject: [PATCH 2/4] feat: enhance Weather Widget test to mock geolocation and increase timeout --- .gitignore | 3 ++- tests/form.spec.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 112703c..73d6529 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,5 @@ yarn-error.log* *.tsbuildinfo next-env.d.ts -tests/reports \ No newline at end of file +tests/reports +playwright-report \ No newline at end of file diff --git a/tests/form.spec.ts b/tests/form.spec.ts index f448aef..6fe1b71 100644 --- a/tests/form.spec.ts +++ b/tests/form.spec.ts @@ -66,11 +66,15 @@ test.describe("Form Submission Tests", () => { }); test.describe("Weather Widget", () => { - test("should display current weather", async ({ page }) => { + test("should display current weather", async ({ page, context }) => { + // Mock geolocation to return a fixed location + await context.grantPermissions(["geolocation"]); + await context.setGeolocation({ latitude: 40.7128, longitude: -74.006 }); + await page.goto("/form"); // Wait for the weather widget to load - await page.waitForSelector("text=Current Weather"); + await page.waitForSelector("text=Current Weather", { timeout: 5000 }); // Check if temperature and wind speed are displayed const temperature = await page.locator("text=Temperature:").isVisible(); From 8f63cbbde8a1cd6c751164fc98b75133f5219c70 Mon Sep 17 00:00:00 2001 From: Nandini Chatterjee Date: Wed, 30 Apr 2025 15:15:31 +0100 Subject: [PATCH 3/4] feat: update Weather Widget test to reduce timeout and validate weather data format --- tests/form.spec.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/form.spec.ts b/tests/form.spec.ts index 6fe1b71..ac30260 100644 --- a/tests/form.spec.ts +++ b/tests/form.spec.ts @@ -74,14 +74,20 @@ test.describe("Weather Widget", () => { await page.goto("/form"); // Wait for the weather widget to load - await page.waitForSelector("text=Current Weather", { timeout: 5000 }); + await page.waitForSelector("text=Current Weather", { timeout: 3000 }); // Check if temperature and wind speed are displayed - const temperature = await page.locator("text=Temperature:").isVisible(); - const windSpeed = await page.locator("text=Wind Speed:").isVisible(); - - expect(temperature).toBeTruthy(); - expect(windSpeed).toBeTruthy(); + const temperatureText = await page + .locator("text=Temperature:") + .last() + .textContent(); + const windSpeedText = await page + .locator("text=Wind Speed:") + .last() + .textContent(); + + expect(temperatureText).toMatch(/Temperature: \d+\.\d+°C/); + expect(windSpeedText).toMatch(/Wind Speed: \d+\.\d+ km\/h/); }); }); From 458a4f7562509b685701031356ebb0f5460485ab Mon Sep 17 00:00:00 2001 From: Nandini Chatterjee Date: Wed, 30 Apr 2025 17:49:00 +0100 Subject: [PATCH 4/4] style: standardize quotation marks in playwright.config.ts --- playwright.config.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/playwright.config.ts b/playwright.config.ts index 87b07da..2728909 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,13 +1,11 @@ -import { defineConfig } from '@playwright/test'; +import { defineConfig } from "@playwright/test"; export default defineConfig({ webServer: { - command: 'npm run dev', + command: "npm run dev", port: 3000, reuseExistingServer: true, }, - reporter: [ - ['list'], - ['html', { outputFolder: 'playwright-report' }] - ], + workers: 4, // Specify the number of workers + reporter: [["list"], ["html", { outputFolder: "playwright-report" }]], });