From 84160f2309fa3e0d231a2d82e16f247babebebe3 Mon Sep 17 00:00:00 2001 From: Peter Hanssens Date: Tue, 23 Sep 2025 19:58:34 +1000 Subject: [PATCH] fix: Resolve Playwright test locator specificity issues - Fix 'strict mode violation' errors by using more specific locators - Replace generic text locators with element-specific selectors - Use CSS class selectors for dropdown menu and sidebar - Use element type selectors (h3, p) for better specificity - Add .first() method to handle multiple matching elements - Improve test reliability and reduce false positives --- tests/e2e/comprehensive-demo.spec.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/e2e/comprehensive-demo.spec.ts b/tests/e2e/comprehensive-demo.spec.ts index 98ffdf5..1315a66 100644 --- a/tests/e2e/comprehensive-demo.spec.ts +++ b/tests/e2e/comprehensive-demo.spec.ts @@ -152,8 +152,8 @@ test.describe('Comprehensive Dashboard Demo E2E Tests', () => { await expect(activitySection).toBeVisible(); // Check for activity items - const activityItems = page.locator('div:has-text("Eddie Lake completed Cover page")'); - await expect(activityItems).toBeVisible(); + const activityItems = page.locator('p:has-text("Eddie Lake completed Cover page")'); + await expect(activityItems.first()).toBeVisible(); // Check for timestamps const timestamps = page.locator('text=2 hours ago, text=4 hours ago, text=6 hours ago'); @@ -163,7 +163,7 @@ test.describe('Comprehensive Dashboard Demo E2E Tests', () => { test.describe('Data Table Section', () => { test('should display project documents table', async () => { - const tableSection = page.locator('text=Project Documents'); + const tableSection = page.locator('h3:has-text("Project Documents")'); await expect(tableSection).toBeVisible(); // Check table headers @@ -183,7 +183,7 @@ test.describe('Comprehensive Dashboard Demo E2E Tests', () => { await openMenuButtons.first().click(); // Check that dropdown menu appears - const dropdownMenu = page.locator('div:has-text("Edit"), div:has-text("Copy"), div:has-text("Delete")'); + const dropdownMenu = page.locator('.absolute.top-16.right-4.bg-card'); await expect(dropdownMenu).toBeVisible(); }); @@ -214,7 +214,7 @@ test.describe('Comprehensive Dashboard Demo E2E Tests', () => { await sidebarToggle.click(); // Check that sidebar is hidden/shown - const sidebar = page.locator('div:has-text("Leptos Dashboard")'); + const sidebar = page.locator('.w-64.bg-card'); await expect(sidebar).toBeVisible(); }); });