From 53833f15ea5dda785256570941ac85a51f3eb583 Mon Sep 17 00:00:00 2001 From: Keith Williams Date: Thu, 8 Jan 2026 15:25:03 -0300 Subject: [PATCH] fix: add waitFor calls to prevent flaky time slot selection tests (#26592) * fix: add waitFor calls to prevent flaky time slot selection tests Co-Authored-By: keith@cal.com * refactor: use locator variables to avoid repeating selectors Co-Authored-By: keith@cal.com --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- apps/web/playwright/lib/testUtils.ts | 31 ++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/apps/web/playwright/lib/testUtils.ts b/apps/web/playwright/lib/testUtils.ts index ab55213034..9fff23a255 100644 --- a/apps/web/playwright/lib/testUtils.ts +++ b/apps/web/playwright/lib/testUtils.ts @@ -106,22 +106,35 @@ export function createHttpServer(opts: { requestHandler?: RequestHandler } = {}) } export async function selectFirstAvailableTimeSlotNextMonth(page: Page | Frame) { - // Let current month dates fully render. - await page.getByTestId("incrementMonth").click(); + // Wait for the booker to be ready before interacting + const incrementMonth = page.getByTestId("incrementMonth"); + await incrementMonth.waitFor(); + await incrementMonth.click(); - // Waiting for full month increment - await page.locator('[data-testid="day"][data-disabled="false"]').nth(0).click(); + // Wait for available day to appear after month increment + const firstAvailableDay = page.locator('[data-testid="day"][data-disabled="false"]').nth(0); + await firstAvailableDay.waitFor(); + await firstAvailableDay.click(); - await page.locator('[data-testid="time"]').nth(0).click(); + const firstTimeSlot = page.locator('[data-testid="time"]').nth(0); + await firstTimeSlot.waitFor(); + await firstTimeSlot.click(); } export async function selectSecondAvailableTimeSlotNextMonth(page: Page) { - // Let current month dates fully render. - await page.getByTestId("incrementMonth").click(); + // Wait for the booker to be ready before interacting + const incrementMonth = page.getByTestId("incrementMonth"); + await incrementMonth.waitFor(); + await incrementMonth.click(); - await page.locator('[data-testid="day"][data-disabled="false"]').nth(1).click(); + // Wait for available day to appear after month increment + const secondAvailableDay = page.locator('[data-testid="day"][data-disabled="false"]').nth(1); + await secondAvailableDay.waitFor(); + await secondAvailableDay.click(); - await page.locator('[data-testid="time"]').nth(0).click(); + const firstTimeSlot = page.locator('[data-testid="time"]').nth(0); + await firstTimeSlot.waitFor(); + await firstTimeSlot.click(); } export async function bookEventOnThisPage(page: Page) {