From 20d210b241f37f13bbe67eadc3f0474ac76c644d Mon Sep 17 00:00:00 2001 From: eshfaq-ux <64083614+eshfaq-ux@users.noreply.github.com> Date: Thu, 2 Oct 2025 23:09:06 +0530 Subject: [PATCH] feat: Add generated.test.js --- generated.test.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 generated.test.js diff --git a/generated.test.js b/generated.test.js new file mode 100644 index 0000000..38527bc --- /dev/null +++ b/generated.test.js @@ -0,0 +1,45 @@ +```javascript +import { test, expect } from '@playwright/test'; + +/** + * This test suite verifies the scrolling functionality of the header navigation links. + */ +test.describe('Header Navigation Scrolling', () => { + + // Before each test, navigate to the local HTML file. + test.beforeEach(async ({ page }) => { + // This assumes the test is run from the project root. + // The path points to the file provided in the context. + // Use 'file://' protocol to load a local file. + await page.goto('file://' + process.cwd() + '/source code/webdev.html'); + }); + + // Data-driven approach to test each navigation link. + const navLinksToTest = [ + { linkText: 'About', sectionId: '#about' }, + { linkText: 'Services', sectionId: '#services' }, + { linkText: 'Portfolio', sectionId: '#portfolio' }, + { linkText: 'Contact', sectionId: '#contact' }, + ]; + + // Dynamically generate a test for each item in the array. + for (const navLink of navLinksToTest) { + test(`clicking "${navLink.linkText}" link should scroll to the "${navLink.sectionId}" section`, async ({ page }) => { + // Locate the specific navigation link in the header by its text. + // Using a case-insensitive exact match for robustness. + const linkLocator = page.locator('header nav a', { hasText: new RegExp(`^${navLink.linkText}$`, 'i') }); + + // Locate the target section element that the link should scroll to. + const sectionLocator = page.locator(navLink.sectionId); + + // Perform the click action on the navigation link. + await linkLocator.click(); + + // Assert that the target section is now within the browser's viewport. + // Playwright's `toBeInViewport` automatically waits for the element + // to appear, which handles potential smooth-scrolling animations. + await expect(sectionLocator).toBeInViewport(); + }); + } +}); +``` \ No newline at end of file