-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa70fdd
commit fe1c9d7
Showing
3 changed files
with
30 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
import { Locator, Page } from "@playwright/test"; | ||
import { Locator, Page } from '@playwright/test'; | ||
|
||
export class PromotionCarousel { | ||
private page: Page; | ||
private carouselContainer: Locator; | ||
private slideButtonSelector: string; | ||
private activeSlideSelector: string; | ||
private page: Page; | ||
private carouselContainer: Locator; | ||
private slideButtonSelector: string; | ||
private activeSlideSelector: string; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
this.carouselContainer = this.page.getByTestId('carousel-container'); | ||
// Selector template for the slide navigation buttons | ||
this.slideButtonSelector = 'button[aria-label="Jump to slide {slideNumber}"]'; | ||
// Selector template for the active slide | ||
this.activeSlideSelector = '.carousel-slide.active[data-slide="{slideNumber}"]'; | ||
} | ||
constructor(page: Page) { | ||
this.page = page; | ||
this.carouselContainer = this.page.getByTestId('carousel-container'); | ||
// Selector template for the slide navigation buttons | ||
this.slideButtonSelector = 'button[aria-label="Jump to slide {slideNumber}"]'; | ||
// Selector template for the active slide | ||
this.activeSlideSelector = '.carousel-slide.active[data-slide="{slideNumber}"]'; | ||
} | ||
|
||
/** | ||
* Navigate to a specific slide in the carousel. | ||
* @param slideNumber - The slide number to navigate to. | ||
*/ | ||
async goToSlide(slideNumber: number): Promise<void> { | ||
// Construct the selector for the slide button | ||
const slideButton = this.slideButtonSelector.replace('{slideNumber}', slideNumber.toString()); | ||
/** | ||
* Navigate to a specific slide in the carousel. | ||
* @param slideNumber - The slide number to navigate to. | ||
*/ | ||
async goToSlide(slideNumber: number): Promise<void> { | ||
// Construct the selector for the slide button | ||
const slideButton = this.slideButtonSelector.replace('{slideNumber}', slideNumber.toString()); | ||
|
||
// Wait for the carousel container to be visible | ||
await this.carouselContainer.waitFor({ state: 'visible', timeout: 10000 }); | ||
// Wait for the carousel container to be visible | ||
await this.carouselContainer.waitFor({ state: 'visible', timeout: 10000 }); | ||
|
||
// Click the button to navigate to the desired slide | ||
await this.page.click(slideButton); | ||
// Click the button to navigate to the desired slide | ||
await this.page.click(slideButton); | ||
|
||
// Ensure the carousel is on the correct slide | ||
const activeSlide = this.activeSlideSelector.replace('{slideNumber}', slideNumber.toString()); | ||
await this.page.waitForSelector(activeSlide, { timeout: 5000 }); | ||
} | ||
// Ensure the carousel is on the correct slide | ||
const activeSlide = this.activeSlideSelector.replace('{slideNumber}', slideNumber.toString()); | ||
await this.page.waitForSelector(activeSlide, { timeout: 5000 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters