AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(frontend): start smoke e2e users with the tab intros already seen (#15902)
Reinier van der Leer7f719e3ce3ed
diff --git a/autogpt_platform/frontend/src/playwright/auth-happy-path.spec.ts b/autogpt_platform/frontend/src/playwright/auth-happy-path.spec.tsindex c076df25f5..72209a21a3 100644--- a/autogpt_platform/frontend/src/playwright/auth-happy-path.spec.ts+++ b/autogpt_platform/frontend/src/playwright/auth-happy-path.spec.ts@@ -2,11 +2,7 @@ import { expect, test } from "./coverage-fixture";import { getSeededTestUser } from "./credentials/accounts";import { BuildPage } from "./pages/build.page";import { LoginPage } from "./pages/login.page";-import {- advanceToRoleStep,- dismissTabIntros,- skipOnboardingIfPresent,-} from "./utils/onboarding";+import { advanceToRoleStep, skipOnboardingIfPresent } from "./utils/onboarding";import { signupTestUser } from "./utils/signup";test("auth happy path: user can sign up with a fresh account", async ({@@ -87,8 +83,6 @@ test("auth happy path: multi-tab logout clears shared builder sessions", async (const page1 = await context.newPage();const page2 = await context.newPage();- await dismissTabIntros(page1);- await dismissTabIntros(page2);const buildPage = new BuildPage(page1);const recordWebSocketErrors =diff --git a/autogpt_platform/frontend/src/playwright/coverage-fixture.ts b/autogpt_platform/frontend/src/playwright/coverage-fixture.tsindex deef6e1c43..0aa0e3216c 100644--- a/autogpt_platform/frontend/src/playwright/coverage-fixture.ts+++ b/autogpt_platform/frontend/src/playwright/coverage-fixture.ts@@ -1,11 +1,9 @@import { test as base } from "@playwright/test";import { addCoverageReport } from "monocart-reporter";-import { dismissTabIntros } from "./utils/onboarding";const test = base.extend<{ autoTestFixture: void }>({autoTestFixture: [async ({ page }, use) => {- await dismissTabIntros(page);let hasCoverage = false;try {await page.coverage.startJSCoverage({ resetOnNavigation: false });diff --git a/autogpt_platform/frontend/src/playwright/pages/login.page.ts b/autogpt_platform/frontend/src/playwright/pages/login.page.tsindex d878f84a86..61faa9c940 100644--- a/autogpt_platform/frontend/src/playwright/pages/login.page.ts+++ b/autogpt_platform/frontend/src/playwright/pages/login.page.ts@@ -3,7 +3,10 @@ import {getSeededTestUser,type SeededTestAccountKey,} from "../credentials/accounts";-import { skipOnboardingIfPresent } from "../utils/onboarding";+import {+ dismissTabIntrosViaAPI,+ skipOnboardingIfPresent,+} from "../utils/onboarding";export class LoginPage {constructor(private page: Page) {}@@ -82,7 +85,10 @@ export class LoginPage {await this.page.waitForLoadState("load", { timeout: 10_000 });// If redirected to onboarding, complete it via API so tests can proceed+ const wasOnOnboarding = this.page.url().includes("/onboarding");await skipOnboardingIfPresent(this.page, "/marketplace");+ // Seeded users are past onboarding but have not seen the tab intros.+ if (!wasOnOnboarding) await dismissTabIntrosViaAPI(this.page);console.log("➡️ Navigating to /marketplace ...");await this.page.goto("/marketplace", { timeout: 20_000 });diff --git a/autogpt_platform/frontend/src/playwright/utils/auth.ts b/autogpt_platform/frontend/src/playwright/utils/auth.tsindex 873c2cbebd..8bc4c5eee1 100644--- a/autogpt_platform/frontend/src/playwright/utils/auth.ts+++ b/autogpt_platform/frontend/src/playwright/utils/auth.ts@@ -9,7 +9,7 @@ import {} from "../credentials/accounts";import { signupTestUser } from "./signup";import { getBrowser } from "./get-browser";-import { skipOnboardingIfPresent } from "./onboarding";+import { dismissTabIntrosViaAPI, skipOnboardingIfPresent } from "./onboarding";export interface TestUser {email: string;@@ -173,11 +173,14 @@ async function authStateHasLiveSession(await page.goto("/marketplace");await page.waitForLoadState("domcontentloaded");await skipOnboardingIfPresent(page, "/marketplace");- return await page+ const isLive = await page.getByTestId("profile-popout-menu-trigger").waitFor({ state: "visible", timeout: 10_000 }).then(() => true).catch(() => false);+ // A state stored before its user's intros were marked seen would meet one.+ if (isLive) await dismissTabIntrosViaAPI(page);+ return isLive;} finally {await page.close();await context.close();diff --git a/autogpt_platform/frontend/src/playwright/utils/onboarding.test.ts b/autogpt_platform/frontend/src/playwright/utils/onboarding.test.tsdeleted file mode 100644index 7580d3a407..0000000000--- a/autogpt_platform/frontend/src/playwright/utils/onboarding.test.ts+++ /dev/null@@ -1,107 +0,0 @@-import type { Locator, Page } from "@playwright/test";-import { describe, expect, it, vi } from "vitest";--import { dismissTabIntros } from "./onboarding";--type ButtonHandle = Awaited<ReturnType<Locator["elementHandles"]>>[number];--function createButton() {- return {- press: vi.fn<ButtonHandle["press"]>().mockResolvedValue(undefined),- dispose: vi.fn<ButtonHandle["dispose"]>().mockResolvedValue(undefined),- };-}--async function registerIntroHandler() {- const elementHandles = vi.fn<Locator["elementHandles"]>();- const intro = {- getByRole: vi.fn().mockReturnValue({ elementHandles }),- } as unknown as Locator;- const addLocatorHandler = vi- .fn<Page["addLocatorHandler"]>()- .mockResolvedValue(undefined);- const page = {- getByTestId: vi.fn().mockReturnValue(intro),- addLocatorHandler,- } as unknown as Page;-- await dismissTabIntros(page);- const handler = addLocatorHandler.mock.calls[0][1];- return { elementHandles, invoke: () => handler(intro) };-}--describe("dismissTabIntros", () => {- it.each([- "locator.elementHandles: Unable to adopt element handle from a different document",- "locator.elementHandles: Execution context was destroyed, most likely because of a navigation",- ])("recovers from a navigation during button lookup: %s", async (message) => {- const { elementHandles, invoke } = await registerIntroHandler();- let rejectLookup!: (error: Error) => void;- const lookup = new Promise<ButtonHandle[]>((_, reject) => {- rejectLookup = reject;- });- const newDocumentButton = createButton();- elementHandles- .mockReturnValueOnce(lookup)- .mockResolvedValueOnce([newDocumentButton as unknown as ButtonHandle]);-- const interruptedHandler = invoke();- const result = expect(interruptedHandler).resolves.toBeUndefined();- rejectLookup(new Error(message));- await result;-- await invoke();-- expect(elementHandles).toHaveBeenCalledTimes(2);- expect(newDocumentButton.press).toHaveBeenCalledExactlyOnceWith("Enter");- expect(newDocumentButton.dispose).toHaveBeenCalledOnce();- });-- it.each([- "Element is not attached to the DOM",- "Execution context was destroyed, most likely because of a navigation",- ])("releases a button detached during dismissal: %s", async (message) => {- const { elementHandles, invoke } = await registerIntroHandler();- const oldButton = createButton();- const newButton = createButton();- oldButton.press.mockRejectedValueOnce(new Error(message));- elementHandles- .mockResolvedValueOnce([oldButton as unknown as ButtonHandle])- .mockResolvedValueOnce([newButton as unknown as ButtonHandle]);-- await expect(invoke()).resolves.toBeUndefined();- expect(oldButton.dispose).toHaveBeenCalledOnce();- await invoke();-- expect(newButton.press).toHaveBeenCalledExactlyOnceWith("Enter");- expect(newButton.dispose).toHaveBeenCalledOnce();- });-- it("allows an overlay to disappear before its button is found", async () => {- const { elementHandles, invoke } = await registerIntroHandler();- elementHandles.mockResolvedValueOnce([]);-- await expect(invoke()).resolves.toBeUndefined();- });-- it.each([- new Error("Target page, context or browser has been closed"),- "unexpected lookup failure",- ])("preserves unexpected lookup failures: %s", async (error) => {- const { elementHandles, invoke } = await registerIntroHandler();- elementHandles.mockRejectedValueOnce(error);-- await expect(invoke()).rejects.toBe(error);- });-- it("preserves unexpected press failures and releases the handle", async () => {- const { elementHandles, invoke } = await registerIntroHandler();- const button = createButton();- const error = new Error("Unexpected keyboard failure");- elementHandles.mockResolvedValueOnce([button as unknown as ButtonHandle]);- button.press.mockRejectedValueOnce(error);-- await expect(invoke()).rejects.toBe(error);- expect(button.dispose).toHaveBeenCalledOnce();- });-});diff --git a/autogpt_platform/frontend/src/playwright/utils/onboarding.ts b/autogpt_platform/frontend/src/playwright/utils/onboarding.tsindex 1493f1d855..f5d404af7a 100644--- a/autogpt_platform/frontend/src/playwright/utils/onboarding.ts+++ b/autogpt_platform/frontend/src/playwright/utils/onboarding.ts@@ -1,31 +1,12 @@-import { type ElementHandle, Page, expect } from "@playwright/test";+import { Page, expect } from "@playwright/test";-export async function dismissTabIntros(page: Page) {- await page.addLocatorHandler(- page.getByTestId("tab-intro-overlay"),- async (intro) => {- let button: ElementHandle<Node> | undefined;- try {- [button] = await intro- .getByRole("button", { name: "Got it", exact: true })- .elementHandles();- if (!button) return;- // A click can intercept its own handler after the outer wait expires.- await button.press("Enter");- } catch (error) {- if (- !(error instanceof Error) ||- !/Element is not attached to the DOM|Execution context was destroyed|Unable to adopt element handle from a different document/.test(- error.message,- )- )- throw error;- } finally {- await button?.dispose();- }- },- );-}+// First-visit cards that cover the page; marked seen up front, as+// journeys/journey-user.ts does, so none can open over a test's next click.+const TAB_INTRO_STEPS = [+ "AGENTS_TAB_INTRO",+ "MARKETPLACE_TAB_INTRO",+ "BUILD_TAB_INTRO",+];function resolveAppUrl(page: Page, destination: string) {const baseURL =@@ -45,13 +26,31 @@ function resolveAppUrl(page: Page, destination: string) {* the page's request context, which inherits the browser's auth cookies.*/export async function completeOnboardingViaAPI(page: Page) {- await page.request.post(+ await completeOnboardingStep(page, "ONBOARDING_COMPLETE");+}++/**+ * Mark the Library, Marketplace and Build tab intros as seen for the signed-in+ * user. Takes effect from the next page load.+ */+export async function dismissTabIntrosViaAPI(page: Page) {+ for (const step of TAB_INTRO_STEPS) {+ await completeOnboardingStep(page, step);+ }+}++async function completeOnboardingStep(page: Page, step: string) {+ const response = await page.request.post(resolveAppUrl(page, "/api/proxy/api/onboarding/step"),{headers: { "Content-Type": "application/json" },- params: { step: "ONBOARDING_COMPLETE" },+ params: { step },},);+ expect(+ response.ok(),+ `onboarding step ${step} failed: ${response.status()}`,+ ).toBe(true);}/**@@ -67,6 +66,7 @@ export async function skipOnboardingIfPresent(if (!url.includes("/onboarding")) return;await completeOnboardingViaAPI(page);+ await dismissTabIntrosViaAPI(page);await page.goto(resolveAppUrl(page, destination));await page.waitForLoadState("domcontentloaded", { timeout: 10000 });}diff --git a/autogpt_platform/frontend/src/playwright/utils/signup.ts b/autogpt_platform/frontend/src/playwright/utils/signup.tsindex 75d6ddf288..698aa878f8 100644--- a/autogpt_platform/frontend/src/playwright/utils/signup.ts+++ b/autogpt_platform/frontend/src/playwright/utils/signup.ts@@ -3,7 +3,7 @@ import { getSelectors } from "./selectors";import { isVisible } from "./assertion";import { BuildPage } from "../pages/build.page";import { NavBar } from "../pages/navbar.page";-import { skipOnboardingIfPresent } from "./onboarding";+import { dismissTabIntrosViaAPI, skipOnboardingIfPresent } from "./onboarding";import { expect } from "@playwright/test";export function isAuthenticatedAppURL(currentURL: string) {@@ -88,6 +88,13 @@ export async function signupTestUser(.waitFor({ state: "visible", timeout: 10000 });}+ // skipOnboardingIfPresent covers /onboarding, where an open wizard must not+ // race these writes; the reload makes the open page read them.+ if (!currentUrl.includes("/onboarding")) {+ await dismissTabIntrosViaAPI(page);+ await page.reload();+ }+if (withAgent) {// Create a dummy agent for each new userawait new NavBar(page).clickBuildLink();