{children}
diff --git a/autogpt_platform/frontend/src/tests/pages/library.page.ts b/autogpt_platform/frontend/src/tests/pages/library.page.ts
index 03e98598b4..17a265d590 100644
--- a/autogpt_platform/frontend/src/tests/pages/library.page.ts
+++ b/autogpt_platform/frontend/src/tests/pages/library.page.ts
@@ -465,9 +465,13 @@ export async function navigateToAgentByName(
export async function clickRunButton(page: Page): Promise {
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
+ // Wait for sidebar loading to complete before detecting buttons.
+ // During sidebar loading, the "New task" button appears transiently
+ // even for agents with no items, then switches to "Setup your task"
+ // once loading finishes. Waiting for network idle ensures the page
+ // has settled into its final state.
+ await page.waitForLoadState("networkidle");
+
const setupTaskButton = page.getByRole("button", {
name: /Setup your task/i,
});
@@ -475,8 +479,7 @@ export async function clickRunButton(page: Page): Promise {
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
+ // Wait for any of the buttons to appear
try {
await Promise.race([
setupTaskButton.waitFor({ state: "visible", timeout: 15000 }),
@@ -490,7 +493,7 @@ export async function clickRunButton(page: Page): Promise {
);
}
- // Now check which button is visible and click it
+ // Check which button is visible and click it
if (await setupTaskButton.isVisible()) {
await setupTaskButton.click();
const startTaskButton = page
@@ -534,7 +537,9 @@ export async function runAgent(page: Page): Promise {
export async function waitForAgentPageLoad(page: Page): Promise {
await page.waitForURL(/.*\/library\/agents\/[^/]+/);
- await page.getByTestId("Run actions").isVisible({ timeout: 10000 });
+ // Wait for sidebar data to finish loading so the page settles
+ // into its final state (empty view vs sidebar view)
+ await page.waitForLoadState("networkidle");
}
export async function getAgentName(page: Page): Promise {