Skip to content

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): Fix flaky agent-activity tests by targeting correct agent (#11790)

Nicholas Tindle088b9998dc2b
diff --git a/autogpt_platform/frontend/src/tests/agent-activity.spec.ts b/autogpt_platform/frontend/src/tests/agent-activity.spec.ts
index e91fceb35a..96c19a8020 100644
--- a/autogpt_platform/frontend/src/tests/agent-activity.spec.ts
+++ b/autogpt_platform/frontend/src/tests/agent-activity.spec.ts
@@ -39,10 +39,9 @@ test.beforeEach(async ({ page }) => {
await page.waitForTimeout(1000);
await page.goto("/library");
- await LibraryPage.clickFirstAgent(page);
+ // Navigate to the specific agent we just created, not just the first one
+ await LibraryPage.navigateToAgentByName(page, "Test Agent");
await LibraryPage.waitForAgentPageLoad(page);
- const { getRole } = getSelectors(page);
- await isVisible(getRole("heading", "Test Agent"), 8000);
});
test("shows badge with count when agent is running", async ({ page }) => {
diff --git a/autogpt_platform/frontend/src/tests/pages/library.page.ts b/autogpt_platform/frontend/src/tests/pages/library.page.ts
index b9af750990..3a7695ec3a 100644
--- a/autogpt_platform/frontend/src/tests/pages/library.page.ts
+++ b/autogpt_platform/frontend/src/tests/pages/library.page.ts
@@ -450,45 +450,72 @@ export async function navigateToAgentByName(
agentName: string,
): Promise<void> {
const agentCard = getAgentCards(page).filter({ hasText: agentName }).first();
+ // Wait for the agent card to be visible before clicking
+ // This handles async loading of agents after page navigation
+ await agentCard.waitFor({ state: "visible", timeout: 15000 });
await agentCard.click();
}
export async function clickRunButton(page: Page): Promise<void> {
const { getId } = getSelectors(page);
+ // Wait for page to stabilize and buttons to render
+ // The NewAgentLibraryView shows either "Setup your task" (empty state)
+ // or "New task" (with items) button
const setupTaskButton = page.getByRole("button", {
name: /Setup your task/i,
});
+ const newTaskButton = page.getByRole("button", { name: /New task/i });
+ const runButton = getId("agent-run-button");
+ const runAgainButton = getId("run-again-button");
+ // Use Promise.race with waitFor to wait for any of the buttons to appear
+ // This handles the async rendering in CI environments
+ try {
+ await Promise.race([
+ setupTaskButton.waitFor({ state: "visible", timeout: 15000 }),
+ newTaskButton.waitFor({ state: "visible", timeout: 15000 }),
+ runButton.waitFor({ state: "visible", timeout: 15000 }),
+ runAgainButton.waitFor({ state: "visible", timeout: 15000 }),
+ ]);
+ } catch {
+ throw new Error(
+ "Could not find run/start task button - none of the expected buttons appeared",
+ );
+ }
+
+ // Now check which button is visible and click it
if (await setupTaskButton.isVisible()) {
await setupTaskButton.click();
const startTaskButton = page
.getByRole("button", { name: /Start Task/i })
.first();
+ await startTaskButton.waitFor({ state: "visible", timeout: 10000 });
await startTaskButton.click();
return;
}
- const newTaskButton = page.getByRole("button", { name: /New task/i });
if (await newTaskButton.isVisible()) {
await newTaskButton.click();
const startTaskButton = page
.getByRole("button", { name: /Start Task/i })
.first();
+ await startTaskButton.waitFor({ state: "visible", timeout: 10000 });
await startTaskButton.click();
return;
}
- const runButton = getId("agent-run-button");
- const runAgainButton = getId("run-again-button");
-
if (await runButton.isVisible()) {
await runButton.click();
- } else if (await runAgainButton.isVisible()) {
+ return;
+ }
+
+ if (await runAgainButton.isVisible()) {
await runAgainButton.click();
- } else {
- throw new Error("Could not find run/start task button");
+ return;
}
+
+ throw new Error("Could not find run/start task button");
}
export async function clickNewRunButton(page: Page): Promise<void> {