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/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" }]], }); diff --git a/tests/form.spec.ts b/tests/form.spec.ts index 3da3458..ac30260 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,48 @@ test.describe("Form Submission Tests", () => { await expect(page.locator('input[name="email"]')).toHaveValue(""); }); }); + +test.describe("Weather Widget", () => { + 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", { timeout: 3000 }); + + // Check if temperature and wind speed are displayed + 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/); + }); +}); + +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(); + }); +});