From 303fc247359dbbb4a52a9b1af2d1198c37f80f86 Mon Sep 17 00:00:00 2001 From: JennyNou Date: Wed, 18 Mar 2026 10:42:38 -0400 Subject: [PATCH] Fix logic for scheduling appointments --- playwright-tests/pages/SchedulePage.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/playwright-tests/pages/SchedulePage.ts b/playwright-tests/pages/SchedulePage.ts index 5c816ef9..e48a3a8a 100644 --- a/playwright-tests/pages/SchedulePage.ts +++ b/playwright-tests/pages/SchedulePage.ts @@ -56,13 +56,20 @@ export class SchedulePage extends BasePage { // Select in shop and schedule async scheduleInShop(appointmentDetails?: IAppointmentDetails){ - if (await this.inShopButton.isVisible() && appointmentDetails?.serviceLocation !== ServiceLocation.DropOff) { + if (await this.inShopButton.isVisible()) { + await this.inShopButton.waitFor({ state: 'visible', timeout: 5000 }); await this.inShopButton.click(); - await (await this.getTimeSlot(1)).click(); + await (await this.getFirstNonDropOffTimeSlot()).click(); + } else if (await this.inShopButton.isHidden() && appointmentDetails?.serviceLocation === ServiceLocation.InShop) { + await (await this.getFirstNonDropOffTimeSlot()).click(); } else if (appointmentDetails?.serviceLocation === ServiceLocation.DropOff) { - await this.inShopButton.isVisible(); + if (await this.inShopButton.isVisible()){ + await this.inShopButton.waitFor({ state: 'visible', timeout: 5000 }); await this.inShopButton.click(); - await this.dropOffButton.isVisible() ? await this.dropOffButton.click() : null; + } else { + await this.dropOffButton.waitFor({ state: 'visible', timeout: 5000 }); + await this.dropOffButton.isVisible() ? await this.dropOffButton.click() : await (await this.getFirstNonDropOffTimeSlot()).click(); // drop off is available in the morning for same day so this is here to avoid flaky tests + } } else { await this.selectFirstAvailableTime(); } @@ -89,7 +96,9 @@ export class SchedulePage extends BasePage { } } - async getTimeSlot(index: number): Promise { - return this.page.locator('.time-slot-button').nth(index); + async getFirstNonDropOffTimeSlot(): Promise { + const timeSlots = this.page.locator('.time-slot-button'); + const nonDropOff = timeSlots.filter({ hasNotText: /Drop & Go/i }); + return nonDropOff.first(); } } \ No newline at end of file