From 48cf9de00034715a2f7da9820975f2e2bc0a2168 Mon Sep 17 00:00:00 2001 From: Anshuman Pandey <54475686+pandeymangg@users.noreply.github.com> Date: Thu, 25 Jan 2024 15:06:03 +0530 Subject: [PATCH] fix: e2e flakyness (#1961) --- apps/web/playwright/action.spec.ts | 17 +++++++++++++++++ apps/web/playwright/js.spec.ts | 2 ++ apps/web/playwright/survey.spec.ts | 7 +++++-- apps/web/playwright/team.spec.ts | 8 +++++--- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/apps/web/playwright/action.spec.ts b/apps/web/playwright/action.spec.ts index 14c83424c7..0c50abfecc 100644 --- a/apps/web/playwright/action.spec.ts +++ b/apps/web/playwright/action.spec.ts @@ -16,6 +16,7 @@ const createNoCodeActionByCSSSelector = async ( await skipOnboarding(page); await page.getByRole("link", { name: "Actions & Attributes" }).click(); + await page.waitForURL(/\/environments\/[^/]+\/actions/); // Add Action button await page.getByRole("button", { name: "Add Action" }).click(); @@ -36,6 +37,8 @@ const createNoCodeActionByCSSSelector = async ( await expect(page.locator("[name='noCodeConfig.cssSelector.value']")).toBeVisible(); await page.locator("[name='noCodeConfig.cssSelector.value']").fill(selector); await page.getByRole("button", { name: "Track Action", exact: true }).click(); + await page.waitForLoadState("networkidle"); + await page.waitForTimeout(500); }; const createNoCodeActionByPageURL = async ( @@ -55,6 +58,7 @@ const createNoCodeActionByPageURL = async ( await skipOnboarding(page); await page.getByRole("link", { name: "Actions & Attributes" }).click(); + await page.waitForURL(/\/environments\/[^/]+\/actions/); // Add Action button await page.getByRole("button", { name: "Add Action" }).click(); @@ -86,6 +90,8 @@ const createNoCodeActionByPageURL = async ( // User clicks the Track Action button await page.getByRole("button", { name: "Track Action", exact: true }).click(); + await page.waitForLoadState("networkidle"); + await page.waitForTimeout(500); }; const createNoCodeActionByInnerText = async ( @@ -101,6 +107,7 @@ const createNoCodeActionByInnerText = async ( await skipOnboarding(page); await page.getByRole("link", { name: "Actions & Attributes" }).click(); + await page.waitForURL(/\/environments\/[^/]+\/actions/); // Add Action button await page.getByRole("button", { name: "Add Action" }).click(); @@ -121,6 +128,8 @@ const createNoCodeActionByInnerText = async ( await expect(page.locator("[name='noCodeConfig.innerHtml.value']")).toBeVisible(); await page.locator("[name='noCodeConfig.innerHtml.value']").fill(innerText); await page.getByRole("button", { name: "Track Action", exact: true }).click(); + await page.waitForLoadState("networkidle"); + await page.waitForTimeout(500); }; const getActionButtonLocator = (page: Page, actionName: string) => { @@ -147,6 +156,7 @@ test.describe("Create and Edit No Code Action by CSS Selector", async () => { const { email, password } = users.action[0]; await login(page, email, password); await page.getByRole("link", { name: "Actions & Attributes" }).click(); + await page.waitForURL(/\/environments\/[^/]+\/actions/); const actionButton = getActionButtonLocator(page, actions.create.noCode.cssSelector.name); await expect(actionButton).toBeVisible(); @@ -191,6 +201,7 @@ test.describe("Create and Edit No Code Action by Page URL", async () => { await login(page, email, password); await page.getByRole("link", { name: "Actions & Attributes" }).click(); + await page.waitForURL(/\/environments\/[^/]+\/actions/); const actionButton = getActionButtonLocator(page, actions.create.noCode.pageURL.name); await expect(actionButton).toBeVisible(); @@ -238,6 +249,7 @@ test.describe("Create and Edit No Code Action by Inner Text", async () => { await login(page, email, password); await page.getByRole("link", { name: "Actions & Attributes" }).click(); + await page.waitForURL(/\/environments\/[^/]+\/actions/); const actionButton = getActionButtonLocator(page, actions.create.noCode.innerText.name); await expect(actionButton).toBeVisible(); @@ -267,6 +279,7 @@ test.describe("Create and Edit Code Action", async () => { await skipOnboarding(page); await page.getByRole("link", { name: "Actions & Attributes" }).click(); + await page.waitForURL(/\/environments\/[^/]+\/actions/); // Add Action button await page.getByRole("button", { name: "Add Action" }).click(); @@ -281,11 +294,14 @@ test.describe("Create and Edit Code Action", async () => { await page.getByLabel("Description").fill(actions.create.code.description); await page.getByRole("button", { name: "Track Action", exact: true }).click(); + await page.waitForLoadState("networkidle"); + await page.waitForTimeout(500); }); test("Edit Code Action", async ({ page }) => { await login(page, email, password); await page.getByRole("link", { name: "Actions & Attributes" }).click(); + await page.waitForURL(/\/environments\/[^/]+\/actions/); const actionButton = getActionButtonLocator(page, actions.create.code.name); await expect(actionButton).toBeVisible(); @@ -321,6 +337,7 @@ test.describe("Create and Delete Action", async () => { await login(page, email, password); await page.getByRole("link", { name: "Actions & Attributes" }).click(); + await page.waitForURL(/\/environments\/[^/]+\/actions/); const actionButton = getActionButtonLocator(page, actions.delete.noCode.name); await expect(actionButton).toBeVisible(); diff --git a/apps/web/playwright/js.spec.ts b/apps/web/playwright/js.spec.ts index 50fb190f94..62ebba9cc8 100644 --- a/apps/web/playwright/js.spec.ts +++ b/apps/web/playwright/js.spec.ts @@ -113,6 +113,8 @@ test.describe("JS Package Test", async () => { // Formbricks Modal is not visible await expect(page.getByText("Powered by Formbricks")).not.toBeVisible({ timeout: 10000 }); + await page.waitForLoadState("networkidle"); + await page.waitForTimeout(500); }); test("Admin validates Response", async ({ page }) => { diff --git a/apps/web/playwright/survey.spec.ts b/apps/web/playwright/survey.spec.ts index d4996fd705..cb8504c5d7 100644 --- a/apps/web/playwright/survey.spec.ts +++ b/apps/web/playwright/survey.spec.ts @@ -1,6 +1,5 @@ import { surveys, users } from "@/playwright/utils/mock"; import { expect, test } from "@playwright/test"; -import path from "path"; import { signUpAndLogin, skipOnboarding } from "./utils/helper"; @@ -246,7 +245,11 @@ test.describe("Survey Create & Submit Response", async () => { await expect( page.locator("label").filter({ hasText: "Click or drag to upload files." }).locator("div").nth(0) ).toBeVisible(); - await page.locator("input[type=file]").setInputFiles(path.join(__dirname, "survey.spec.ts")); + await page.locator("input[type=file]").setInputFiles({ + name: "file.txt", + mimeType: "text/plain", + buffer: Buffer.from("this is test"), + }); await page.getByText("Uploading...").waitFor({ state: "hidden" }); await page.getByRole("button", { name: "Finish" }).click(); diff --git a/apps/web/playwright/team.spec.ts b/apps/web/playwright/team.spec.ts index bba3eab223..e47854c428 100644 --- a/apps/web/playwright/team.spec.ts +++ b/apps/web/playwright/team.spec.ts @@ -34,9 +34,11 @@ test.describe("Invite, accept and remove team member", async () => { await page.getByLabel("Email Address").fill(invites.addMember.email); await page.getByRole("button", { name: "Send Invitation", exact: true }).click(); + await page.waitForLoadState("networkidle"); + await page.waitForTimeout(500); }); - test("Copy Invite Link", async ({ page }) => { + test("Copy invite Link", async ({ page }) => { await login(page, email, password); const dropdownTrigger = page.locator("#userDropdownTrigger"); @@ -71,7 +73,7 @@ test.describe("Invite, accept and remove team member", async () => { } }); - test("Accept Invite", async ({ page }) => { + test("Accept invite", async ({ page }) => { const { email, name, password } = users.team[1]; page.goto(inviteLink); @@ -85,7 +87,7 @@ test.describe("Invite, accept and remove team member", async () => { await skipOnboarding(page); }); - test("Remove Member", async ({ page }) => { + test("Remove member", async ({ page }) => { await login(page, email, password); const dropdownTrigger = page.locator("#userDropdownTrigger");