-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add generated test case #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
Comment on lines
+10
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use The current string concatenation for building the file:// URL is fragile and not cross-platform compatible. Use Node.js's First, add the import at the top of the file: import path from 'path'; Then update the path construction: 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');
+ await page.goto('file://' + path.join(process.cwd(), 'source code', 'webdev.html'));
}); 🤖 Prompt for AI Agents
|
||
|
||
// 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(); | ||
}); | ||
} | ||
}); | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove markdown code fences from JavaScript file.
This file contains markdown code fence syntax (
```javascript
and```
) which will cause parse errors. A.test.js
file should contain only JavaScript code.Remove the markdown wrapper:
Also applies to: 45-45
🤖 Prompt for AI Agents