From c3909ccc70977ad06b16af4c9ef53d3572101695 Mon Sep 17 00:00:00 2001 From: zomars Date: Wed, 11 May 2022 10:46:52 -0600 Subject: [PATCH] Multiple E2E improvements --- apps/web/playwright/booking-pages.test.ts | 12 ++---------- apps/web/playwright/hash-my-url.test.ts | 6 +----- apps/web/playwright/integrations-stripe.test.ts | 6 +----- apps/web/playwright/lib/testUtils.ts | 8 ++------ apps/web/playwright/reschedule.test.ts | 6 +----- .../embeds/embed-core/playwright/lib/testUtils.ts | 6 +----- tests/config/playwright.config.ts | 10 +++++++--- turbo.json | 2 +- 8 files changed, 16 insertions(+), 40 deletions(-) diff --git a/apps/web/playwright/booking-pages.test.ts b/apps/web/playwright/booking-pages.test.ts index 6c0115b0..0ad40b00 100644 --- a/apps/web/playwright/booking-pages.test.ts +++ b/apps/web/playwright/booking-pages.test.ts @@ -44,11 +44,7 @@ test.describe("free user", () => { await bookTimeSlot(page); // Make sure we're navigated to the success page - await page.waitForNavigation({ - url(url) { - return url.pathname.endsWith("/success"); - }, - }); + await expect(page.locator("[data-testid=success-page]")).toBeVisible(); // return to same time spot booking page await page.goto(bookingUrl); @@ -98,11 +94,7 @@ test.describe("pro user", () => { await bookTimeSlot(page); // Make sure we're navigated to the success page - await page.waitForNavigation({ - url(url) { - return url.pathname.endsWith("/success"); - }, - }); + await expect(page.locator("[data-testid=success-page]")).toBeVisible(); }); test("can reschedule a booking", async ({ page }) => { await bookFirstEvent(page); diff --git a/apps/web/playwright/hash-my-url.test.ts b/apps/web/playwright/hash-my-url.test.ts index a66d41c9..4890c0a8 100644 --- a/apps/web/playwright/hash-my-url.test.ts +++ b/apps/web/playwright/hash-my-url.test.ts @@ -46,11 +46,7 @@ test.describe("hash my url", () => { await bookTimeSlot(page); // Make sure we're navigated to the success page - await page.waitForNavigation({ - url(url) { - return url.pathname.endsWith("/success"); - }, - }); + await expect(page.locator("[data-testid=success-page]")).toBeVisible(); }); test("hash regenerates after successful booking", async ({ page }) => { diff --git a/apps/web/playwright/integrations-stripe.test.ts b/apps/web/playwright/integrations-stripe.test.ts index f6426591..d9dc7f2a 100644 --- a/apps/web/playwright/integrations-stripe.test.ts +++ b/apps/web/playwright/integrations-stripe.test.ts @@ -71,11 +71,7 @@ test.describe.serial("Stripe integration", () => { await page.click('button:has-text("Pay now")'); // Make sure we're navigated to the success page - await page.waitForNavigation({ - url(url) { - return url.pathname.endsWith("/success"); - }, - }); + await expect(page.locator("[data-testid=success-page]")).toBeVisible(); }); todo("Pending payment booking should not be confirmed by default"); diff --git a/apps/web/playwright/lib/testUtils.ts b/apps/web/playwright/lib/testUtils.ts index 88d25817..ffe116ee 100644 --- a/apps/web/playwright/lib/testUtils.ts +++ b/apps/web/playwright/lib/testUtils.ts @@ -1,4 +1,4 @@ -import { Page, test } from "@playwright/test"; +import { expect, Page, test } from "@playwright/test"; import { createServer, IncomingMessage, ServerResponse } from "http"; export function todo(title: string) { @@ -99,11 +99,7 @@ export async function bookFirstEvent(page: Page) { await page.press('[name="email"]', "Enter"); // Make sure we're navigated to the success page - await page.waitForNavigation({ - url(url) { - return url.pathname.endsWith("/success"); - }, - }); + await expect(page.locator("[data-testid=success-page]")).toBeVisible(); } export const bookTimeSlot = async (page: Page) => { diff --git a/apps/web/playwright/reschedule.test.ts b/apps/web/playwright/reschedule.test.ts index c8be2197..d21cdbaa 100644 --- a/apps/web/playwright/reschedule.test.ts +++ b/apps/web/playwright/reschedule.test.ts @@ -153,11 +153,7 @@ test.describe("Reschedule Tests", async () => { await page.locator('[data-testid="confirm-reschedule-button"]').click(); - await page.waitForNavigation({ - url(url) { - return url.pathname.endsWith("/success"); - }, - }); + await expect(page.locator("[data-testid=success-page]")).toBeVisible(); await expect(page).toHaveURL(/.*success/); diff --git a/packages/embeds/embed-core/playwright/lib/testUtils.ts b/packages/embeds/embed-core/playwright/lib/testUtils.ts index 62797e4f..1ab43dad 100644 --- a/packages/embeds/embed-core/playwright/lib/testUtils.ts +++ b/packages/embeds/embed-core/playwright/lib/testUtils.ts @@ -83,11 +83,7 @@ export async function bookFirstEvent(username: string, frame: Frame, page: Page) const responseObj = await response.json(); const bookingId = responseObj.uid; // Make sure we're navigated to the success page - await frame.waitForNavigation({ - url(url) { - return url.pathname.endsWith("/success"); - }, - }); + await expect(page.locator("[data-testid=success-page]")).toBeVisible(); expect(await page.screenshot()).toMatchSnapshot("success-page.png"); return bookingId; } diff --git a/tests/config/playwright.config.ts b/tests/config/playwright.config.ts index 9e19b486..512bed0c 100644 --- a/tests/config/playwright.config.ts +++ b/tests/config/playwright.config.ts @@ -1,5 +1,6 @@ import { devices, PlaywrightTestConfig } from "@playwright/test"; import { addAliases } from "module-alias"; +import * as os from "os"; import * as path from "path"; // Add aliases for the paths specified in the tsconfig.json file. @@ -19,11 +20,14 @@ const testDir = path.join(__dirname, "..", "..", "apps/web/playwright"); const DEFAULT_NAVIGATION_TIMEOUT = 5000; +const headless = !!process.env.CI || !!process.env.PLAYWRIGHT_HEADLESS; + const config: PlaywrightTestConfig = { forbidOnly: !!process.env.CI, retries: 1, - workers: 1, + workers: os.cpus().length, timeout: 60_000, + maxFailures: headless ? 3 : undefined, reporter: [ [process.env.CI ? "github" : "list"], ["html", { outputFolder: "./playwright/reports/playwright-html-report", open: "never" }], @@ -38,10 +42,10 @@ const config: PlaywrightTestConfig = { reuseExistingServer: !process.env.CI, }, use: { - baseURL: "http://localhost:3000", + baseURL: "http://localhost:3000/", locale: "en-US", trace: "retain-on-failure", - headless: !!process.env.CI || !!process.env.PLAYWRIGHT_HEADLESS, + headless, }, projects: [ { diff --git a/turbo.json b/turbo.json index c818c78f..e2257f66 100644 --- a/turbo.json +++ b/turbo.json @@ -132,7 +132,7 @@ }, "test-e2e": { "cache": false, - "dependsOn": ["@calcom/web#test", "@calcom/web#build", "@calcom/prisma#db-reset"] + "dependsOn": ["@calcom/prisma#db-reset", "@calcom/web#test", "@calcom/web#build"] }, "type-check": { "outputs": []