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): Library e2e specs wait for their search to apply before clicking a card (#15153)
Reinier van der Leerbac86aeb2839
diff --git a/autogpt_platform/frontend/src/playwright/library-happy-path.spec.ts b/autogpt_platform/frontend/src/playwright/library-happy-path.spec.tsindex 18f7c430f5..4fe9834b3e 100644--- a/autogpt_platform/frontend/src/playwright/library-happy-path.spec.ts+++ b/autogpt_platform/frontend/src/playwright/library-happy-path.spec.ts@@ -255,6 +255,35 @@ test("library happy path: user can import an agent file into Library", async ({expect(importedAgent.name).toContain("E2E Import Agent");});+test("library happy path: searching narrows the list to the matching agent", async ({+ page,+}) => {+ test.setTimeout(60000);++ const agentName = createUniqueAgentName("E2E Search Agent");+ const otherAgentName = createUniqueAgentName("E2E Search Other Agent");+ await createDeterministicCalculatorSavedAgent(page, otherAgentName, "other");+ await createDeterministicCalculatorSavedAgent(page, agentName, "result");++ const libraryPage = new LibraryPage(page);+ await page.goto("/library");+ const cards = page.getByTestId("library-agent-card");+ await expect(cards.filter({ hasText: otherAgentName })).toBeVisible({+ timeout: 15000,+ });++ await libraryPage.searchAgents(agentName);++ // Read once, without retrying: every spec clicks a card right after+ // searchAgents returns, so the unfiltered list must already be gone.+ const cardNames = await page+ .getByTestId("library-agent-card-name")+ .allTextContents();+ expect(cardNames.filter((name) => !name.includes(agentName))).toEqual([]);+ await expect(cards).toHaveCount(1);+ await expect(cards.filter({ hasText: agentName })).toBeVisible();+});+test("library happy path: user can open the imported or saved agent from Library in builder", async ({page,}) => {@@ -373,7 +402,6 @@ test("library happy path: user can edit a saved agent from Library and keep chanawait page.goto("/library");await libraryPage.waitForAgentsToLoad();await libraryPage.searchAgents(agentName);- await libraryPage.waitForAgentsToLoad();const agentCard = page.getByTestId("library-agent-card")diff --git a/autogpt_platform/frontend/src/playwright/pages/library.page.ts b/autogpt_platform/frontend/src/playwright/pages/library.page.tsindex c9d097aa5b..740aa976f4 100644--- a/autogpt_platform/frontend/src/playwright/pages/library.page.ts+++ b/autogpt_platform/frontend/src/playwright/pages/library.page.ts@@ -1,4 +1,4 @@-import { expect, Locator, Page } from "@playwright/test";+import { expect, Locator, Page, Response } from "@playwright/test";import { getSeededTestUser } from "../credentials/accounts";import { getSelectors } from "../utils/selectors";import { BasePage } from "./base.page";@@ -90,10 +90,20 @@ export class LibraryPage extends BasePage {async searchAgents(searchTerm: string): Promise<void> {console.log(`searching for agents with term: ${searchTerm}`);- const { getRole } = getSelectors(this.page);+ const { getId, getRole } = getSelectors(this.page);const searchInput = getRole("textbox", "Search agents");+ // Cards render only after hydration; text typed before it never reaches onChange.+ await expect(getId("library-agent-card").first()).toBeVisible({+ timeout: 15000,+ });+ // The search applies after a debounce; until then the unfiltered list is clickable.+ const searchApplied = this.page.waitForResponse(+ (response) => isAgentListResponseFor(response, searchTerm),+ { timeout: 15000 },+ );await searchInput.fill(searchTerm);await expect(searchInput).toHaveValue(searchTerm);+ await searchApplied;}async clearSearch(): Promise<void> {@@ -444,6 +454,17 @@ export class LibraryPage extends BasePage {}}+function isAgentListResponseFor(+ response: Response,+ searchTerm: string,+): boolean {+ const url = new URL(response.url());+ return (+ url.pathname.endsWith("/api/library/agents") &&+ url.searchParams.get("search_term") === searchTerm+ );+}+// Locator functionsexport function getLibraryTab(page: Page): Locator {return page.locator('a[href="/library"]');@@ -1168,7 +1189,6 @@ export async function importAgentFromFile(await page.goto("/library");await libraryPage.searchAgents(agentName);- await libraryPage.waitForAgentsToLoad();// Look up the specific imported card directly rather than calling// getAgents() in a loop. getAgents() iterates every visible card and@@ -1225,7 +1245,6 @@ export async function openSavedAgentInLibrary(await page.goto("/library");await libraryPage.waitForAgentsToLoad();await libraryPage.searchAgents(agentName);- await libraryPage.waitForAgentsToLoad();await navigateToAgentByName(page, agentName);await waitForAgentPageLoad(page, agentName);}diff --git a/autogpt_platform/frontend/src/playwright/publish-happy-path.spec.ts b/autogpt_platform/frontend/src/playwright/publish-happy-path.spec.tsindex 577bb7dbc1..d90669894b 100644--- a/autogpt_platform/frontend/src/playwright/publish-happy-path.spec.ts+++ b/autogpt_platform/frontend/src/playwright/publish-happy-path.spec.ts@@ -21,7 +21,6 @@ test("publish happy path: user can submit, track, and delete an agent submissionawait page.goto("/library");await libraryPage.waitForAgentsToLoad();await libraryPage.searchAgents(publishableAgentName);- await libraryPage.waitForAgentsToLoad();const createdAgent = page.getByTestId("library-agent-card")