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.

test(frontend): e2e tests for library page (#10355)

Abhimanyu Yadav98482664742b
diff --git a/autogpt_platform/backend/test/e2e_test_data.py b/autogpt_platform/backend/test/e2e_test_data.py
index dbc840406a..2e54055705 100644
--- a/autogpt_platform/backend/test/e2e_test_data.py
+++ b/autogpt_platform/backend/test/e2e_test_data.py
@@ -332,6 +332,8 @@ class TestDataCreator:
if is_dummy_input:
graph_name = f"DummyInput {graph_name}"
+ graph_name = f"{graph_name} Agents"
+
graph = Graph(
id=graph_id,
name=graph_name,
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/components/LibraryActionSubHeader/LibraryActionSubHeader.tsx b/autogpt_platform/frontend/src/app/(platform)/library/components/LibraryActionSubHeader/LibraryActionSubHeader.tsx
index bb76233b6a..be1ebe1aef 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/components/LibraryActionSubHeader/LibraryActionSubHeader.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/components/LibraryActionSubHeader/LibraryActionSubHeader.tsx
@@ -15,7 +15,10 @@ export default function LibraryActionSubHeader({
<span className="font-poppin w-[96px] text-[18px] font-semibold leading-[28px] text-neutral-800">
My agents
</span>
- <span className="w-[70px] font-sans text-[14px] font-normal leading-6">
+ <span
+ className="w-[70px] font-sans text-[14px] font-normal leading-6"
+ data-testid="agents-count"
+ >
{agentCount} agents
</span>
</div>
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/components/LibrarySearchBar/LibrarySearchBar.tsx b/autogpt_platform/frontend/src/app/(platform)/library/components/LibrarySearchBar/LibrarySearchBar.tsx
index 099f036052..4a1422b5ea 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/components/LibrarySearchBar/LibrarySearchBar.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/components/LibrarySearchBar/LibrarySearchBar.tsx
@@ -8,6 +8,7 @@ export default function LibrarySearchBar(): React.ReactNode {
useLibrarySearchbar();
return (
<div
+ data-testid="search-bar"
onClick={() => inputRef.current?.focus()}
className="relative z-[21] mx-auto flex h-[50px] w-full max-w-[500px] flex-1 cursor-pointer items-center rounded-[45px] bg-[#EDEDED] px-[24px] py-[10px]"
>
@@ -23,6 +24,7 @@ export default function LibrarySearchBar(): React.ReactNode {
onChange={handleSearchInput}
className="flex-1 border-none font-sans text-[16px] font-normal leading-7 shadow-none focus:shadow-none focus:ring-0"
type="text"
+ data-testid="library-textbox"
placeholder="Search agents"
/>
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/components/LibrarySortMenu/LibrarySortMenu.tsx b/autogpt_platform/frontend/src/app/(platform)/library/components/LibrarySortMenu/LibrarySortMenu.tsx
index d1d973d295..f86b26f5f5 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/components/LibrarySortMenu/LibrarySortMenu.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/components/LibrarySortMenu/LibrarySortMenu.tsx
@@ -14,7 +14,7 @@ import { useLibrarySortMenu } from "./useLibrarySortMenu";
export default function LibrarySortMenu(): React.ReactNode {
const { handleSortChange } = useLibrarySortMenu();
return (
- <div className="flex items-center">
+ <div className="flex items-center" data-testid="sort-by-dropdown">
<span className="hidden whitespace-nowrap sm:inline">sort by</span>
<Select onValueChange={handleSortChange}>
<SelectTrigger className="ml-1 w-fit space-x-1 border-none px-0 text-base underline underline-offset-4 shadow-none">
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/components/LibraryUploadAgentDialog/LibraryUploadAgentDialog.tsx b/autogpt_platform/frontend/src/app/(platform)/library/components/LibraryUploadAgentDialog/LibraryUploadAgentDialog.tsx
index e095da4f5f..41fc7e6e85 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/components/LibraryUploadAgentDialog/LibraryUploadAgentDialog.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/components/LibraryUploadAgentDialog/LibraryUploadAgentDialog.tsx
@@ -49,7 +49,11 @@ export default function LibraryUploadAgentDialog(): React.ReactNode {
return (
<Dialog open={isOpen} onOpenChange={setIsOpen}>
<DialogTrigger asChild>
- <Button variant="primary" className="w-fit sm:w-[177px]">
+ <Button
+ data-testid="upload-agent-button"
+ variant="primary"
+ className="w-fit sm:w-[177px]"
+ >
<Upload className="h-5 w-5 sm:mr-2" />
<span className="hidden items-center sm:inline-flex">
Upload an agent
diff --git a/autogpt_platform/frontend/src/tests/assets/testing_agent.json b/autogpt_platform/frontend/src/tests/assets/testing_agent.json
new file mode 100644
index 0000000000..c39308d821
--- /dev/null
+++ b/autogpt_platform/frontend/src/tests/assets/testing_agent.json
@@ -0,0 +1,48 @@
+{
+ "id": "0f919347-86ce-4218-8d80-617dc6e57cc7",
+ "version": 1,
+ "is_active": true,
+ "name": "Testing agent",
+ "description": "We use this agent for test purpose only",
+ "nodes": [
+ {
+ "id": "c5e2d556-80e7-4fa6-841f-fe6cdfc75004",
+ "block_id": "b1ab9b19-67a6-406d-abf5-2dba76d00c79",
+ "input_default": {
+ "round_result": false
+ },
+ "metadata": {
+ "position": {
+ "x": 804.8000000000001,
+ "y": 539.6
+ }
+ },
+ "input_links": [],
+ "output_links": [],
+ "graph_id": "0f919347-86ce-4218-8d80-617dc6e57cc7",
+ "graph_version": 1,
+ "webhook_id": null,
+ "webhook": null
+ }
+ ],
+ "links": [],
+ "forked_from_id": null,
+ "forked_from_version": null,
+ "sub_graphs": [],
+ "input_schema": {
+ "type": "object",
+ "properties": {},
+ "required": []
+ },
+ "output_schema": {
+ "type": "object",
+ "properties": {},
+ "required": []
+ },
+ "credentials_input_schema": {
+ "properties": {},
+ "title": "TestingagentCredentialsInputSchema",
+ "type": "object"
+ },
+ "has_webhook_trigger": false
+}
diff --git a/autogpt_platform/frontend/src/tests/global-setup.ts b/autogpt_platform/frontend/src/tests/global-setup.ts
index 8a8cb48675..901eb117ef 100644
--- a/autogpt_platform/frontend/src/tests/global-setup.ts
+++ b/autogpt_platform/frontend/src/tests/global-setup.ts
@@ -1,10 +1,6 @@
import { FullConfig } from "@playwright/test";
import { createTestUsers, saveUserPool, loadUserPool } from "./utils/auth";
-/**
- * Global setup function that runs before all tests
- * Creates test users and saves them to file system
- */
async function globalSetup(config: FullConfig) {
console.log("🚀 Starting global test setup...");
diff --git a/autogpt_platform/frontend/src/tests/library.spec.ts b/autogpt_platform/frontend/src/tests/library.spec.ts
new file mode 100644
index 0000000000..5709740535
--- /dev/null
+++ b/autogpt_platform/frontend/src/tests/library.spec.ts
@@ -0,0 +1,292 @@
+import { LibraryPage } from "./pages/library.page";
+import path from "path";
+import test, { expect } from "@playwright/test";
+import { TEST_CREDENTIALS } from "./credentials";
+import { LoginPage } from "./pages/login.page";
+import { getSelectors } from "./utils/selectors";
+import { hasUrl } from "./utils/assertion";
+
+test.describe("Library", () => {
+ let libraryPage: LibraryPage;
+
+ test.beforeEach(async ({ page }) => {
+ libraryPage = new LibraryPage(page);
+
+ await page.goto("/login");
+ const loginPage = new LoginPage(page);
+ await loginPage.login(TEST_CREDENTIALS.email, TEST_CREDENTIALS.password);
+ await hasUrl(page, "/marketplace");
+ });
+
+ test("library page loads successfully", async ({ page }) => {
+ const { getId } = getSelectors(page);
+ await page.goto("/library");
+
+ await expect(getId("search-bar").first()).toBeVisible();
+ await expect(getId("upload-agent-button").first()).toBeVisible();
+ await expect(getId("sort-by-dropdown").first()).toBeVisible();
+ });
+
+ test("agents are visible and cards work correctly", async ({ page }) => {
+ await page.goto("/library");
+
+ const agents = await libraryPage.getAgents();
+ expect(agents.length).toBeGreaterThan(0);
+
+ const firstAgent = agents[0];
+ expect(firstAgent).toBeTruthy();
+
+ await libraryPage.clickAgent(firstAgent);
+ await hasUrl(page, `/library/agents/${firstAgent.id}`);
+
+ await libraryPage.navigateToLibrary();
+
+ const updatedAgents = await libraryPage.getAgents();
+ const agentWithBuilder = updatedAgents.find((agent) =>
+ agent.openInBuilderUrl.includes("/build"),
+ );
+
+ if (agentWithBuilder) {
+ await libraryPage.clickOpenInBuilder(agentWithBuilder);
+ await page.waitForURL("**/build**");
+ test.expect(page.url()).toContain(`/build`);
+ }
+ });
+
+ test("pagination works correctly", async ({ page }) => {
+ await page.goto("/library");
+
+ const paginationResult = await libraryPage.testPagination();
+
+ if (paginationResult.initialCount >= 10) {
+ expect(paginationResult.finalCount).toBeGreaterThanOrEqual(
+ paginationResult.initialCount,
+ );
+ expect(paginationResult.hasMore).toBeTruthy();
+ }
+
+ await libraryPage.isPaginationWorking();
+
+ const allAgents = await libraryPage.getAgentsWithPagination();
+ test.expect(allAgents.length).toBeGreaterThan(0);
+
+ const displayedCount = await libraryPage.getAgentCount();
+ test.expect(allAgents.length).toEqual(displayedCount);
+ });
+
+ test("sorting works correctly", async ({ page }) => {
+ await page.goto("/library");
+
+ const initialAgents = await libraryPage.getAgents();
+ expect(initialAgents.length).toBeGreaterThan(0);
+
+ await libraryPage.selectSortOption(page, "Creation Date");
+ await libraryPage.waitForAgentsToLoad();
+
+ const creationDateSortOption = await libraryPage.getCurrentSortOption();
+ expect(creationDateSortOption).toContain("Creation Date");
+
+ const creationDateAgents = await libraryPage.getAgents();
+ expect(creationDateAgents.length).toBeGreaterThan(0);
+
+ await libraryPage.selectSortOption(page, "Last Modified");
+ await libraryPage.waitForAgentsToLoad();
+
+ const lastModifiedSortOption = await libraryPage.getCurrentSortOption();
+ expect(lastModifiedSortOption).toContain("Last Modified");
+
+ const lastModifiedAgents = await libraryPage.getAgents();
+ expect(lastModifiedAgents.length).toBeGreaterThan(0);
+
+ if (initialAgents.length > 1) {
+ const initialFirstAgentId = initialAgents[0].id;
+ const creationDateFirstAgentId = creationDateAgents[0].id;
+ const lastModifiedFirstAgentId = lastModifiedAgents[0].id;
+
+ expect(
+ creationDateFirstAgentId !== initialFirstAgentId ||
+ lastModifiedFirstAgentId !== initialFirstAgentId ||
+ creationDateFirstAgentId !== lastModifiedFirstAgentId,
+ ).toBeTruthy();
+ }
+
+ expect(creationDateAgents.length).toEqual(initialAgents.length);
+ expect(lastModifiedAgents.length).toEqual(initialAgents.length);
+ });
+
+ test("searching works correctly", async ({ page }) => {
+ await page.goto("/library");
+
+ const allAgents = await libraryPage.getAgents();
+ expect(allAgents.length).toBeGreaterThan(0);
+
+ const firstAgent = allAgents[0];
+ await libraryPage.searchAgents(firstAgent.name);
+ await libraryPage.waitForAgentsToLoad();
+
+ const searchResults = await libraryPage.getAgents();
+ expect(searchResults.length).toBeGreaterThan(0);
+
+ const foundAgent = searchResults.find(
+ (agent) => agent.name === firstAgent.name,
+ );
+ expect(foundAgent).toBeTruthy();
+
+ const searchValue = await libraryPage.getSearchValue();
+ expect(searchValue).toBe(firstAgent.name);
+
+ const partialSearchTerm = firstAgent.name.substring(0, 3);
+ await libraryPage.searchAgents(partialSearchTerm);
+ await libraryPage.waitForAgentsToLoad();
+
+ const partialSearchResults = await libraryPage.getAgents();
+ expect(partialSearchResults.length).toBeGreaterThan(0);
+
+ const matchingAgents = partialSearchResults.filter((agent) =>
+ agent.name.toLowerCase().includes(partialSearchTerm.toLowerCase()),
+ );
+ expect(matchingAgents.length).toBeGreaterThan(0);
+
+ await libraryPage.searchAgents("nonexistentagentnamethatdoesnotexist");
+ const noResults = await libraryPage.getAgentCount();
+ expect(noResults).toBe(0);
+
+ const hasNoAgentsMessage = await libraryPage.hasNoAgentsMessage();
+ expect(hasNoAgentsMessage).toBeTruthy();
+
+ await libraryPage.clearSearch();
+ await libraryPage.waitForAgentsToLoad();
+
+ const clearedSearchResults = await libraryPage.getAgents();
+ test.expect(clearedSearchResults.length).toEqual(allAgents.length);
+
+ const clearedSearchValue = await libraryPage.getSearchValue();
+ test.expect(clearedSearchValue).toBe("");
+ });
+
+ test("pagination while searching works correctly", async ({ page }) => {
+ await page.goto("/library");
+
+ const allAgents = await libraryPage.getAgents();
+ test.expect(allAgents.length).toBeGreaterThan(0);
+
+ const searchTerm = "Agent";
+
+ await libraryPage.searchAgents(searchTerm);
+ await libraryPage.waitForAgentsToLoad();
+
+ const initialSearchResults = await libraryPage.getAgents();
+ expect(initialSearchResults.length).toBeGreaterThan(0);
+
+ const matchingResults = initialSearchResults.filter((agent) =>
+ agent.name.toLowerCase().includes(searchTerm.toLowerCase()),
+ );
+ expect(matchingResults.length).toEqual(initialSearchResults.length);
+
+ const searchPaginationResult = await libraryPage.testPagination();
+
+ if (searchPaginationResult.initialCount >= 10) {
+ expect(searchPaginationResult.finalCount).toBeGreaterThanOrEqual(
+ searchPaginationResult.initialCount,
+ );
+
+ const allPaginatedResults = await libraryPage.getAgentsWithPagination();
+ const matchingPaginatedResults = allPaginatedResults.filter((agent) =>
+ agent.name.toLowerCase().includes(searchTerm.toLowerCase()),
+ );
+ expect(matchingPaginatedResults.length).toEqual(
+ allPaginatedResults.length,
+ );
+ } else {
+ }
+
+ await libraryPage.scrollAndWaitForNewAgents();
+
+ const finalSearchResults = await libraryPage.getAgents();
+ const finalMatchingResults = finalSearchResults.filter((agent) =>
+ agent.name.toLowerCase().includes(searchTerm.toLowerCase()),
+ );
+ expect(finalMatchingResults.length).toEqual(finalSearchResults.length);
+
+ const preservedSearchValue = await libraryPage.getSearchValue();
+ expect(preservedSearchValue).toBe(searchTerm);
+
+ await libraryPage.clearSearch();
+ await libraryPage.waitForAgentsToLoad();
+
+ const clearedResults = await libraryPage.getAgents();
+ expect(clearedResults.length).toBeGreaterThanOrEqual(
+ initialSearchResults.length,
+ );
+ });
+
+ test("uploading an agent works correctly", async ({ page }) => {
+ await page.goto("/library");
+
+ await libraryPage.openUploadDialog();
+
+ expect(await libraryPage.isUploadDialogVisible()).toBeTruthy();
+ expect(await libraryPage.isUploadButtonEnabled()).toBeFalsy();
+
+ const testAgentName = "Test Upload Agent";
+ const testAgentDescription = "This is a test agent uploaded via automation";
+ await libraryPage.fillUploadForm(testAgentName, testAgentDescription);
+
+ const fileInput = page.locator('input[type="file"]');
+ const testAgentPath = path.resolve(
+ __dirname,
+ "assets",
+ "testing_agent.json",
+ );
+ await fileInput.setInputFiles(testAgentPath);
+
+ await page.waitForTimeout(1000);
+
+ expect(await libraryPage.isUploadButtonEnabled()).toBeTruthy();
+
+ await page.getByRole("button", { name: "Upload Agent" }).click();
+
+ await page.waitForURL("**/build**", { timeout: 10000 });
+ expect(page.url()).toContain("/build");
+
+ await page.goto("/library");
+
+ await libraryPage.searchAgents(testAgentName);
+ await libraryPage.waitForAgentsToLoad();
+
+ const searchResults = await libraryPage.getAgents();
+ test.expect(searchResults.length).toBeGreaterThan(0);
+
+ const uploadedAgent = searchResults.find((agent) =>
+ agent.name.includes(testAgentName),
+ );
+ test.expect(uploadedAgent).toBeTruthy();
+
+ if (uploadedAgent) {
+ test.expect(uploadedAgent.name).toContain(testAgentName);
+ test.expect(uploadedAgent.description).toContain(testAgentDescription);
+ test.expect(uploadedAgent.seeRunsUrl).toBeTruthy();
+ test.expect(uploadedAgent.openInBuilderUrl).toBeTruthy();
+
+ await libraryPage.clickAgent(uploadedAgent);
+ await page.waitForURL(`**/library/agents/${uploadedAgent.id}**`, {
+ timeout: 10000,
+ });
+
+ await page.getByRole("button", { name: "Delete agent" }).click();
+ await page.waitForTimeout(500);
+ await page.getByRole("button", { name: "Delete" }).click();
+
+ await page.waitForTimeout(1000);
+ await libraryPage.navigateToLibrary();
+ await libraryPage.waitForAgentsToLoad();
+
+ await libraryPage.searchAgents(testAgentName);
+ await libraryPage.waitForAgentsToLoad();
+ const deletedSearchResults = await libraryPage.getAgentCount();
+ expect(deletedSearchResults).toBe(0);
+ }
+ await libraryPage.clearSearch();
+ await libraryPage.waitForAgentsToLoad();
+ });
+});
diff --git a/autogpt_platform/frontend/src/tests/pages/build.page.ts b/autogpt_platform/frontend/src/tests/pages/build.page.ts
index 5c85c5396a..958296d5ac 100644
--- a/autogpt_platform/frontend/src/tests/pages/build.page.ts
+++ b/autogpt_platform/frontend/src/tests/pages/build.page.ts
@@ -403,6 +403,15 @@ export class BuildPage extends BasePage {
};
}
+ async getCalculatorBlockDetails(): Promise<Block> {
+ return {
+ id: "dummy-id-2",
+ name: "Calculator",
+ description: "Calculator",
+ type: "Standard",
+ };
+ }
+
async waitForSaveDialogClose(): Promise<void> {
console.log(`waiting for save dialog to close`);
diff --git a/autogpt_platform/frontend/src/tests/pages/library.page.ts b/autogpt_platform/frontend/src/tests/pages/library.page.ts
index 7ae7fe917f..ef26ad60bf 100644
--- a/autogpt_platform/frontend/src/tests/pages/library.page.ts
+++ b/autogpt_platform/frontend/src/tests/pages/library.page.ts
@@ -1,6 +1,404 @@
+import { BasePage } from "./base.page";
import { Locator, Page } from "@playwright/test";
import { getSelectors } from "../utils/selectors";
+export interface Agent {
+ id: string;
+ name: string;
+ description: string;
+ imageUrl?: string;
+ seeRunsUrl: string;
+ openInBuilderUrl: string;
+}
+
+export class LibraryPage extends BasePage {
+ constructor(page: Page) {
+ super(page);
+ }
+
+ async isLoaded(): Promise<boolean> {
+ console.log(`checking if library page is loaded`);
+ try {
+ await this.page.waitForLoadState("domcontentloaded", { timeout: 10_000 });
+
+ await this.page.waitForSelector('[data-testid="library-textbox"]', {
+ state: "visible",
+ timeout: 10_000,
+ });
+
+ console.log("Library page is loaded successfully");
+ return true;
+ } catch (error) {
+ console.log("Library page failed to load:", error);
+ return false;
+ }
+ }
+
+ async navigateToLibrary(): Promise<void> {
+ await this.page.goto("/library");
+ await this.isLoaded();
+ }
+
+ async getAgentCount(): Promise<number> {
+ const { getId } = getSelectors(this.page);
+ const countText = await getId("agents-count").textContent();
+ const match = countText?.match(/^(\d+)/);
+ return match ? parseInt(match[1], 10) : 0;
+ }
+
+ async getAgentCountByListLength(): Promise<number> {
+ const { getId } = getSelectors(this.page);
+ const agentCards = await getId("library-agent-card").all();
+ return agentCards.length;
+ }
+
+ async searchAgents(searchTerm: string): Promise<void> {
+ console.log(`searching for agents with term: ${searchTerm}`);
+ const { getRole } = getSelectors(this.page);
+ const searchInput = getRole("textbox", "Search agents");
+ await searchInput.fill(searchTerm);
+
+ await this.page.waitForTimeout(500);
+ }
+
+ async clearSearch(): Promise<void> {
+ console.log(`clearing search`);
+ try {
+ // Look for the clear button (X icon)
+ const clearButton = this.page.locator(".lucide.lucide-x");
+ if (await clearButton.isVisible()) {
+ await clearButton.click();
+ } else {
+ // If no clear button, clear the search input directly
+ const searchInput = this.page.getByRole("textbox", {
+ name: "Search agents",
+ });
+ await searchInput.fill("");
+ }
+
+ // Wait for results to update
+ await this.page.waitForTimeout(500);
+ } catch (error) {
+ console.error("Error clearing search:", error);
+ }
+ }
+
+ async selectSortOption(
+ page: Page,
+ sortOption: "Creation Date" | "Last Modified",
+ ): Promise<void> {
+ const { getRole } = getSelectors(page);
+ await getRole("combobox").click();
+
+ await getRole("option", sortOption).click();
+
+ await this.page.waitForTimeout(500);
+ }
+
+ async getCurrentSortOption(): Promise<string> {
+ console.log(`getting current sort option`);
+ try {
+ const sortCombobox = this.page.getByRole("combobox");
+ const currentOption = await sortCombobox.textContent();
+ return currentOption?.trim() || "";
+ } catch (error) {
+ console.error("Error getting current sort option:", error);
+ return "";
+ }
+ }
+
+ async openUploadDialog(): Promise<void> {
+ console.log(`opening upload dialog`);
+ await this.page.getByRole("button", { name: "Upload an agent" }).click();
+
+ // Wait for dialog to appear
+ await this.page.getByRole("dialog", { name: "Upload Agent" }).waitFor({
+ state: "visible",
+ timeout: 5_000,
+ });
+ }
+
+ async closeUploadDialog(): Promise<void> {
+ await this.page.getByRole("button", { name: "Close" }).click();
+
+ await this.page.getByRole("dialog", { name: "Upload Agent" }).waitFor({
+ state: "hidden",
+ timeout: 5_000,
+ });
+ }
+
+ async isUploadDialogVisible(): Promise<boolean> {
+ console.log(`checking if upload dialog is visible`);
+ try {
+ const dialog = this.page.getByRole("dialog", { name: "Upload Agent" });
+ return await dialog.isVisible();
+ } catch {
+ return false;
+ }
+ }
+
+ async fillUploadForm(agentName: string, description: string): Promise<void> {
+ console.log(
+ `filling upload form with name: ${agentName}, description: ${description}`,
+ );
+
+ // Fill agent name
+ await this.page
+ .getByRole("textbox", { name: "Agent name" })
+ .fill(agentName);
+
+ // Fill description
+ await this.page
+ .getByRole("textbox", { name: "Description" })
+ .fill(description);
+ }
+
+ async isUploadButtonEnabled(): Promise<boolean> {
+ console.log(`checking if upload button is enabled`);
+ try {
+ const uploadButton = this.page.getByRole("button", {
+ name: "Upload Agent",
+ });
+ return await uploadButton.isEnabled();
+ } catch {
+ return false;
+ }
+ }
+
+ async getAgents(): Promise<Agent[]> {
+ const { getId } = getSelectors(this.page);
+ const agents: Agent[] = [];
+
+ await getId("library-agent-card")
+ .first()
+ .waitFor({ state: "visible", timeout: 10_000 });
+ const agentCards = await getId("library-agent-card").all();
+
+ for (const card of agentCards) {
+ const name = await card.locator("h3").textContent();
+ const description = await card.locator("p").textContent();
+ const seeRunsLink = card.locator("a", { hasText: "See runs" });
+ const openInBuilderLink = card.locator("a", {
+ hasText: "Open in builder",
+ });
+
+ const seeRunsUrl = await seeRunsLink.getAttribute("href");
+ const openInBuilderUrl = await openInBuilderLink.getAttribute("href");
+
+ if (name && description && seeRunsUrl && openInBuilderUrl) {
+ const idMatch = seeRunsUrl.match(/\/library\/agents\/([^\/]+)/);
+ const id = idMatch ? idMatch[1] : "";
+
+ agents.push({
+ id,
+ name: name.trim(),
+ description: description.trim(),
+ seeRunsUrl,
+ openInBuilderUrl,
+ });
+ }
+ }
+
+ console.log(`found ${agents.length} agents`);
+ return agents;
+ }
+
+ async clickAgent(agent: Agent): Promise<void> {
+ await this.page
+ .getByRole("heading", { name: agent.name, level: 3 })
+ .click();
+ }
+
+ async clickSeeRuns(agent: Agent): Promise<void> {
+ console.log(`clicking see runs for agent: ${agent.name}`);
+
+ // Find the "See runs" link for this specific agent
+ const agentCard = this.page.locator(`[href="${agent.seeRunsUrl}"]`).first();
+ await agentCard.click();
+ }
+
+ async clickOpenInBuilder(agent: Agent): Promise<void> {
+ console.log(`clicking open in builder for agent: ${agent.name}`);
+
+ // Find the "Open in builder" link for this specific agent
+ const builderLink = this.page
+ .locator(`[href="${agent.openInBuilderUrl}"]`)
+ .first();
+ await builderLink.click();
+ }
+
+ async waitForAgentsToLoad(): Promise<void> {
+ const { getId } = getSelectors(this.page);
+ await Promise.race([
+ getId("library-agent-card")
+ .first()
+ .waitFor({ state: "visible", timeout: 10_000 }),
+ getId("agents-count").waitFor({ state: "visible", timeout: 10_000 }),
+ ]);
+ }
+
+ async clickMonitoringLink(): Promise<void> {
+ console.log(`clicking monitoring link in alert`);
+ await this.page.getByRole("link", { name: "here" }).click();
+ }
+
+ async isMonitoringAlertVisible(): Promise<boolean> {
+ console.log(`checking if monitoring alert is visible`);
+ try {
+ const alertText = this.page.locator("text=/Prefer the old experience/");
+ return await alertText.isVisible();
+ } catch {
+ return false;
+ }
+ }
+
+ async getSearchValue(): Promise<string> {
+ console.log(`getting search input value`);
+ try {
+ const searchInput = this.page.getByRole("textbox", {
+ name: "Search agents",
+ });
+ return await searchInput.inputValue();
+ } catch {
+ return "";
+ }
+ }
+
+ async hasNoAgentsMessage(): Promise<boolean> {
+ const { getText } = getSelectors(this.page);
+ const noAgentsText = getText("0 agents");
+ return noAgentsText !== null;
+ }
+
+ async scrollToBottom(): Promise<void> {
+ console.log(`scrolling to bottom to trigger pagination`);
+ await this.page.keyboard.press("End");
+ await this.page.waitForTimeout(1000);
+ }
+
+ async scrollDown(): Promise<void> {
+ console.log(`scrolling down to trigger pagination`);
+ await this.page.keyboard.press("PageDown");
+ await this.page.waitForTimeout(1000);
+ }
+
+ async scrollToLoadMore(): Promise<void> {
+ console.log(`scrolling to load more agents`);
+
+ // Get initial agent count
+ const initialCount = await this.getAgentCount();
+ console.log(`Initial agent count: ${initialCount}`);
+
+ // Scroll down to trigger pagination
+ await this.scrollToBottom();
+
+ // Wait for potential new agents to load
+ await this.page.waitForTimeout(2000);
+
+ // Check if more agents loaded
+ const newCount = await this.getAgentCount();
+ console.log(`New agent count after scroll: ${newCount}`);
+
+ return;
+ }
+
+ async testPagination(): Promise<{
+ initialCount: number;
+ finalCount: number;
+ hasMore: boolean;
+ }> {
+ const initialCount = await this.getAgentCountByListLength();
+ await this.scrollToLoadMore();
+ const finalCount = await this.getAgentCountByListLength();
+
+ const hasMore = finalCount > initialCount;
+ return {
+ initialCount,
+ finalCount,
+ hasMore,
+ };
+ }
+
+ async getAgentsWithPagination(): Promise<Agent[]> {
+ console.log(`getting all agents with pagination`);
+
+ let allAgents: Agent[] = [];
+ let previousCount = 0;
+ let currentCount = 0;
+ const maxAttempts = 5; // Prevent infinite loop
+ let attempts = 0;
+
+ do {
+ previousCount = currentCount;
+
+ // Get current agents
+ const currentAgents = await this.getAgents();
+ allAgents = currentAgents;
+ currentCount = currentAgents.length;
+
+ console.log(`Attempt ${attempts + 1}: Found ${currentCount} agents`);
+
+ // Try to load more by scrolling
+ await this.scrollToLoadMore();
+
+ attempts++;
+ } while (currentCount > previousCount && attempts < maxAttempts);
+
+ console.log(`Total agents found with pagination: ${allAgents.length}`);
+ return allAgents;
+ }
+
+ async waitForPaginationLoad(): Promise<void> {
+ console.log(`waiting for pagination to load`);
+
+ // Wait for any loading states to complete
+ await this.page.waitForTimeout(1000);
+
+ // Wait for agent count to stabilize
+ let previousCount = 0;
+ let currentCount = 0;
+ let stableChecks = 0;
+ const maxChecks = 10;
+
+ while (stableChecks < 3 && stableChecks < maxChecks) {
+ currentCount = await this.getAgentCount();
+
+ if (currentCount === previousCount) {
+ stableChecks++;
+ } else {
+ stableChecks = 0;
+ }
+
+ previousCount = currentCount;
+ await this.page.waitForTimeout(500);
+ }
+
+ console.log(`Pagination load stabilized with ${currentCount} agents`);
+ }
+
+ async scrollAndWaitForNewAgents(): Promise<number> {
+ const initialCount = await this.getAgentCountByListLength();
+
+ await this.scrollDown();
+
+ await this.waitForPaginationLoad();
+
+ const finalCount = await this.getAgentCountByListLength();
+ const newAgentsLoaded = finalCount - initialCount;
+
+ console.log(
+ `Loaded ${newAgentsLoaded} new agents (${initialCount} -> ${finalCount})`,
+ );
+
+ return newAgentsLoaded;
+ }
+
+ async isPaginationWorking(): Promise<boolean> {
+ const newAgentsLoaded = await this.scrollAndWaitForNewAgents();
+ return newAgentsLoaded > 0;
+ }
+}
+
// Locator functions
export function getLibraryTab(page: Page): Locator {
return page.locator('a[href="/library"]');
diff --git a/autogpt_platform/frontend/src/tests/utils/auth.ts b/autogpt_platform/frontend/src/tests/utils/auth.ts
index cb844f7a4b..d3efdaf05e 100644
--- a/autogpt_platform/frontend/src/tests/utils/auth.ts
+++ b/autogpt_platform/frontend/src/tests/utils/auth.ts
@@ -1,8 +1,8 @@
import { faker } from "@faker-js/faker";
-import { chromium, webkit } from "@playwright/test";
import fs from "fs";
import path from "path";
import { signupTestUser } from "./signup";
+import { getBrowser } from "./get-browser";
export interface TestUser {
email: string;
@@ -26,13 +26,7 @@ export async function createTestUser(
const userPassword = password || faker.internet.password({ length: 12 });
try {
- const browserType = process.env.BROWSER_TYPE || "chromium";
-
- const browser =
- browserType === "webkit"
- ? await webkit.launch({ headless: true })
- : await chromium.launch({ headless: true });
-
+ const browser = await getBrowser();
const context = await browser.newContext();
const page = await context.newPage();
diff --git a/autogpt_platform/frontend/src/tests/utils/get-browser.ts b/autogpt_platform/frontend/src/tests/utils/get-browser.ts
new file mode 100644
index 0000000000..aef4778305
--- /dev/null
+++ b/autogpt_platform/frontend/src/tests/utils/get-browser.ts
@@ -0,0 +1,12 @@
+import { chromium, webkit } from "@playwright/test";
+
+export const getBrowser = async () => {
+ const browserType = process.env.BROWSER_TYPE || "chromium";
+
+ const browser =
+ browserType === "webkit"
+ ? await webkit.launch({ headless: true })
+ : await chromium.launch({ headless: true });
+
+ return browser;
+};