-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add generated test case #17
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,68 @@ | ||
```javascript | ||
import { test, expect } from '@playwright/test'; | ||
import path from 'path'; | ||
|
||
// Define the path to the local HTML file | ||
const pageURL = `file://${path.resolve(__dirname, 'source code/index.html')}`; | ||
|
||
test.describe('Hero Carousel Functionality', () => { | ||
|
||
test.beforeEach(async ({ page }) => { | ||
// Navigate to the local HTML file before each test | ||
await page.goto(pageURL); | ||
// Wait for the initial loading spinner to disappear to ensure the page is ready | ||
await expect(page.locator('#spinner')).not.toBeVisible({ timeout: 15000 }); | ||
// Also wait for the carousel itself to be visible | ||
await expect(page.locator('.header-carousel')).toBeVisible(); | ||
}); | ||
|
||
test("Confirm the main hero carousel automatically transitions between slides and that the 'Join Now' and 'Read More' buttons are present and clickable.", async ({ page }) => { | ||
// Step 1: Verify the first slide is active and its buttons are present and clickable. | ||
|
||
// Locate the first slide's heading to confirm it's visible initially. | ||
const firstSlideHeading = page.getByRole('heading', { name: 'The Best Online Learning Platform' }); | ||
await expect(firstSlideHeading).toBeVisible({ timeout: 5000 }); | ||
|
||
// Find the currently active carousel item. | ||
const activeSlide = page.locator('.owl-carousel-item.active'); | ||
|
||
// Verify the "Read More" button is visible and enabled on the active slide. | ||
const readMoreButton = activeSlide.getByRole('link', { name: 'Read More' }); | ||
await expect(readMoreButton).toBeVisible(); | ||
await expect(readMoreButton).toBeEnabled(); | ||
|
||
// Verify the "Join Now" button is visible and enabled on the active slide. | ||
const joinNowButton = activeSlide.getByRole('link', { name: 'Join Now' }); | ||
await expect(joinNowButton).toBeVisible(); | ||
await expect(joinNowButton).toBeEnabled(); | ||
Comment on lines
+27
to
+37
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. Potential race condition with active slide selector. The selector Consider adding a more specific selector or waiting for the transition to stabilize: // Find the currently active carousel item.
- const activeSlide = page.locator('.owl-carousel-item.active');
+ const activeSlide = page.locator('.owl-carousel-item.active').first(); Additionally, consider verifying that only one slide is active before proceeding: // Ensure exactly one active slide before checking buttons
await expect(page.locator('.owl-carousel-item.active')).toHaveCount(1, { timeout: 5000 });
const activeSlide = page.locator('.owl-carousel-item.active'); 🤖 Prompt for AI Agents
|
||
|
||
// Step 2: Verify the carousel transitions to the second slide automatically. | ||
|
||
// Locate the second slide's heading. | ||
const secondSlideHeading = page.getByRole('heading', { name: 'Get Educated Online From Your Home' }); | ||
|
||
// Wait for the second slide's heading to become visible. This confirms the auto-transition. | ||
// Owl Carousel's default autoplay speed is 5 seconds. We'll use a longer timeout to be safe. | ||
await expect(secondSlideHeading).toBeVisible({ timeout: 10000 }); | ||
|
||
// Step 3: Verify the buttons on the newly active second slide are also present and clickable. | ||
|
||
// Re-locate the active slide, which should now be the second one. | ||
const secondActiveSlide = page.locator('.owl-carousel-item.active'); | ||
|
||
// Verify the "Read More" button is visible and enabled on the new active slide. | ||
const secondReadMoreButton = secondActiveSlide.getByRole('link', { name: 'Read More' }); | ||
await expect(secondReadMoreButton).toBeVisible(); | ||
await expect(secondReadMoreButton).toBeEnabled(); | ||
|
||
// Verify the "Join Now" button is visible and enabled on the new active slide. | ||
const secondJoinNowButton = secondActiveSlide.getByRole('link', { name: 'Join Now' }); | ||
await expect(secondJoinNowButton).toBeVisible(); | ||
await expect(secondJoinNowButton).toBeEnabled(); | ||
Comment on lines
+51
to
+61
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. Same race condition issue with active slide selector. The same selector reliability concern applies here. When re-locating the active slide after transition, Apply the same fix as suggested for the first active slide: // Re-locate the active slide, which should now be the second one.
- const secondActiveSlide = page.locator('.owl-carousel-item.active');
+ const secondActiveSlide = page.locator('.owl-carousel-item.active').first(); Or verify count first: await expect(page.locator('.owl-carousel-item.active')).toHaveCount(1, { timeout: 5000 });
const secondActiveSlide = page.locator('.owl-carousel-item.active'); 🤖 Prompt for AI Agents
|
||
|
||
// Finally, confirm the first slide's heading is no longer visible to ensure the transition is complete. | ||
await expect(firstSlideHeading).not.toBeVisible(); | ||
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. 🛠️ Refactor suggestion | 🟠 Major 🧩 Analysis chainVerify the final assertion accounts for cloned slides. Owl Carousel clones slides for seamless infinite looping. The first slide's heading may still exist in the DOM as a clone, which could cause this assertion to fail even after a successful transition. Run the following script to check if the HTML uses Owl Carousel with loop/cloning enabled: If cloning is enabled, consider asserting on the active state instead: // Instead of checking visibility, verify the first slide is no longer active
await expect(firstSlideHeading.locator('xpath=ancestor::*[contains(@class, "owl-carousel-item")]')).not.toHaveClass(/active/); 🏁 Script executed: #!/bin/bash
# Description: Check if Owl Carousel is configured with cloning/looping
# Search for Owl Carousel initialization with loop option
rg -n -A 10 -B 2 '\.owlCarousel\(' 'source code/'
# Also check for data attributes that enable looping
rg -n 'data-loop|data-clone' 'source code/' Length of output: 1291 Assert slide inactive rather than invisible await expect(firstSlideHeading).not.toBeVisible(); with await expect(
firstSlideHeading.locator('xpath=ancestor::*[contains(@class, "owl-carousel-item")]')
).not.toHaveClass(/active/); 🤖 Prompt for AI Agents
|
||
}); | ||
|
||
}); | ||
``` |
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.
Fix the missing semicolon.
There is a syntax error: the statement is missing a semicolon.
Apply this diff to fix the syntax error:
📝 Committable suggestion
🧰 Tools
🪛 Biome (2.1.2)
[error] 6-6: Expected a semicolon or an implicit semicolon after a statement, but found none
An explicit or implicit semicolon is expected here...
...Which is required to end this statement
(parse)
🤖 Prompt for AI Agents