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.

refactor(frontend): e2e tests setup + speed + readability (#10388)

Ubbed3bfad2a106f
diff --git a/.github/workflows/platform-frontend-ci.yml b/.github/workflows/platform-frontend-ci.yml
index 38815b5467..749e5232c0 100644
--- a/.github/workflows/platform-frontend-ci.yml
+++ b/.github/workflows/platform-frontend-ci.yml
@@ -155,8 +155,6 @@ jobs:
needs: setup
strategy:
fail-fast: false
- matrix:
- browser: [chromium, webkit]
steps:
- name: Checkout repository
@@ -208,13 +206,11 @@ jobs:
run: pnpm build --turbo
# uses Turbopack, much faster and safe enough for a test pipeline
- - name: Install Browser '${{ matrix.browser }}'
- run: pnpm playwright install --with-deps ${{ matrix.browser }}
+ - name: Install Browser 'chromium'
+ run: pnpm playwright install --with-deps chromium
- name: Run Playwright tests
- run: pnpm test:no-build --project=${{ matrix.browser }}
- env:
- BROWSER_TYPE: ${{ matrix.browser }}
+ run: pnpm test:no-build
- name: Print Final Docker Compose logs
if: always()
diff --git a/autogpt_platform/frontend/playwright.config.ts b/autogpt_platform/frontend/playwright.config.ts
index 0d01eae519..2462064e08 100644
--- a/autogpt_platform/frontend/playwright.config.ts
+++ b/autogpt_platform/frontend/playwright.config.ts
@@ -21,8 +21,8 @@ export default defineConfig({
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
- /* Opt out of parallel tests on CI. */
- workers: process.env.CI ? 1 : undefined,
+ /* use more workers on CI. */
+ workers: process.env.CI ? 4 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [["html"], ["line"]],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
@@ -36,51 +36,20 @@ export default defineConfig({
bypassCSP: true,
},
/* Maximum time one test can run for */
- timeout: 30000,
+ timeout: 15000,
/* Configure web server to start automatically */
webServer: {
command: "NEXT_PUBLIC_PW_TEST=true pnpm start",
url: "http://localhost:3000",
reuseExistingServer: !process.env.CI,
- timeout: 120 * 1000,
},
/* Configure projects for major browsers */
projects: [
{
name: "chromium",
- use: { ...devices["Desktop Chrome"] },
+ use: { ...devices["Desktop Chrome"], channel: "chromium" },
},
-
- // {
- // name: "firefox",
- // use: { ...devices["Desktop Firefox"] },
- // },
-
- {
- name: "webkit",
- use: { ...devices["Desktop Safari"] },
- },
-
- // /* Test against mobile viewports. */
- // // {
- // // name: 'Mobile Chrome',
- // // use: { ...devices['Pixel 5'] },
- // // },
- // // {
- // // name: 'Mobile Safari',
- // // use: { ...devices['iPhone 12'] },
- // // },
-
- // /* Test against branded browsers. */
- // {
- // name: "Microsoft Edge",
- // use: { ...devices["Desktop Edge"], channel: "msedge" },
- // },
- // {
- // name: 'Google Chrome',
- // use: { ...devices['Desktop Chrome'], channel: 'chrome' },
- // },
],
});
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/components/LibraryAgentCard/LibraryAgentCard.tsx b/autogpt_platform/frontend/src/app/(platform)/library/components/LibraryAgentCard/LibraryAgentCard.tsx
index c9d21d5629..b6419750ad 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/components/LibraryAgentCard/LibraryAgentCard.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/components/LibraryAgentCard/LibraryAgentCard.tsx
@@ -20,7 +20,11 @@ export default function LibraryAgentCard({
},
}: LibraryAgentCardProps) {
return (
- <div className="inline-flex w-full max-w-[434px] flex-col items-start justify-start gap-2.5 rounded-[26px] bg-white transition-all duration-300 hover:shadow-lg dark:bg-transparent dark:hover:shadow-gray-700">
+ <div
+ data-testid="library-agent-card"
+ data-agent-id={id}
+ className="inline-flex w-full max-w-[434px] flex-col items-start justify-start gap-2.5 rounded-[26px] bg-white transition-all duration-300 hover:shadow-lg dark:bg-transparent dark:hover:shadow-gray-700"
+ >
<Link
href={`/library/agents/${id}`}
className="relative h-[200px] w-full overflow-hidden rounded-[20px]"
diff --git a/autogpt_platform/frontend/src/components/CustomNode.tsx b/autogpt_platform/frontend/src/components/CustomNode.tsx
index 21a10b87a9..bf5df316c7 100644
--- a/autogpt_platform/frontend/src/components/CustomNode.tsx
+++ b/autogpt_platform/frontend/src/components/CustomNode.tsx
@@ -719,7 +719,9 @@ export const CustomNode = React.memo(
<div
className={`${blockClasses} ${errorClass} ${statusClass}`}
data-id={`custom-node-${id}`}
+ id={data.block_id}
z-index={1}
+ data-testid={data.block_id}
data-blockid={data.block_id}
data-blockname={data.title}
data-blocktype={data.blockType}
diff --git a/autogpt_platform/frontend/src/components/edit/control/BlocksControl.tsx b/autogpt_platform/frontend/src/components/edit/control/BlocksControl.tsx
index e5c3a3315f..22c82e324a 100644
--- a/autogpt_platform/frontend/src/components/edit/control/BlocksControl.tsx
+++ b/autogpt_platform/frontend/src/components/edit/control/BlocksControl.tsx
@@ -238,7 +238,10 @@ export function BlocksControl({
data-id="blocks-control-search-input"
/>
</div>
- <div className="mt-2 flex flex-wrap gap-2">
+ <div
+ className="mt-2 flex flex-wrap gap-2"
+ data-testid="blocks-categories-list"
+ >
{categories.map((category) => {
const color = getPrimaryCategoryColor([
{ category: category || "All", description: "" },
@@ -248,6 +251,8 @@ export function BlocksControl({
return (
<div
key={category}
+ data-testid="blocks-category"
+ role="button"
className={`cursor-pointer rounded-xl border px-2 py-2 text-xs font-medium dark:border-slate-700 dark:text-white ${colorClass}`}
onClick={() =>
setSelectedCategory(
diff --git a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/AccountMenu.tsx b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/AccountMenu.tsx
index 447358be65..18312607e5 100644
--- a/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/AccountMenu.tsx
+++ b/autogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/AccountMenu.tsx
@@ -49,6 +49,7 @@ export function AccountMenu({
<PopoverContent
id={popupId}
className="flex flex-col items-start justify-start gap-4 rounded-[26px] bg-zinc-400/70 p-4 shadow backdrop-blur-2xl dark:bg-zinc-800/70"
+ data-testid="account-menu-popover"
>
{/* Header with avatar and user info */}
<div className="inline-flex items-center justify-start gap-1 self-stretch">
diff --git a/autogpt_platform/frontend/src/components/node-input-components.tsx b/autogpt_platform/frontend/src/components/node-input-components.tsx
index 5a8c197434..ddd72b19f3 100644
--- a/autogpt_platform/frontend/src/components/node-input-components.tsx
+++ b/autogpt_platform/frontend/src/components/node-input-components.tsx
@@ -79,7 +79,7 @@ const NodeObjectInputTree: FC<NodeObjectInputTreeProps> = ({
className,
}) => {
object ||= ("default" in schema ? schema.default : null) ?? {};
- return (
+ return schema.properties ? (
<div className={cn(className, "w-full flex-col")}>
{Object.entries(schema.properties).map(([propKey, propSchema]) => {
const childKey = selfKey ? `${selfKey}.${propKey}` : propKey;
@@ -108,7 +108,7 @@ const NodeObjectInputTree: FC<NodeObjectInputTreeProps> = ({
);
})}
</div>
- );
+ ) : null;
};
export default NodeObjectInputTree;
@@ -644,7 +644,7 @@ const NodeOneOfDiscriminatorField: FC<{
</SelectContent>
</Select>
- {chosenVariantSchema && (
+ {chosenVariantSchema && chosenVariantSchema.properties && (
<div className={cn(className, "w-full flex-col")}>
{Object.entries(chosenVariantSchema.properties).map(
([someKey, childSchema]) => {
diff --git a/autogpt_platform/frontend/src/tests/build.spec.ts b/autogpt_platform/frontend/src/tests/build.spec.ts
index 84e4f72d15..74d07629cf 100644
--- a/autogpt_platform/frontend/src/tests/build.spec.ts
+++ b/autogpt_platform/frontend/src/tests/build.spec.ts
@@ -3,8 +3,17 @@
//make sure to update the docs! Your autoformmater will break this page,
// so don't run it on this file.
// --8<-- [start:BuildPageExample]
-import { test } from "./fixtures";
+
+import test from "@playwright/test";
import { BuildPage } from "./pages/build.page";
+import { LoginPage } from "./pages/login.page";
+import { getTestUser } from "./utils/auth";
+import { hasUrl } from "./utils/assertion";
+
+test.describe.configure({
+ timeout: 40000,
+ mode: "parallel",
+});
// Reason Ignore: admonishment is in the wrong place visually with correct prettier rules
// prettier-ignore
@@ -13,22 +22,59 @@ test.describe("Build", () => { //(1)!
// Reason Ignore: admonishment is in the wrong place visually with correct prettier rules
// prettier-ignore
- test.beforeEach(async ({ page, loginPage, testUser }) => { //(3)! ts-ignore
+ test.beforeEach(async ({ page }) => { //(3)! ts-ignore
+ const loginPage = new LoginPage(page);
+ const testUser = await getTestUser();
+
buildPage = new BuildPage(page);
// Start each test with login using worker auth
await page.goto("/login"); //(4)!
await loginPage.login(testUser.email, testUser.password);
- await test.expect(page).toHaveURL("/marketplace"); //(5)!
+ await hasUrl(page, "/marketplace"); //(5)!
await buildPage.navbar.clickBuildLink();
- await test.expect(page).toHaveURL("/build");
+ await hasUrl(page, "/build");
await buildPage.waitForPageLoad();
+ await buildPage.closeTutorial();
});
+ // Helper function to add blocks starting with a specific letter
+ async function addBlocksStartingWith(letter: string): Promise<void> {
+ const blockIdsToSkip = await buildPage.getBlocksToSkip();
+ const blockTypesToSkip = ["Input", "Output", "Agent", "AI"];
+ console.log("⚠️ Skipping blocks:", blockIdsToSkip);
+ console.log("⚠️ Skipping block types:", blockTypesToSkip);
+
+ const targetLetter = letter.toLowerCase();
+
+ // Get filtered blocks from API instead of DOM
+ const blocksToAdd = await buildPage.getFilteredBlocksFromAPI(block =>
+ block.name[0].toLowerCase() === targetLetter &&
+ !blockIdsToSkip.includes(block.id) &&
+ !blockTypesToSkip.includes(block.type)
+ );
+
+ await buildPage.openBlocksPanel();
+
+ console.log(`Adding ${blocksToAdd.length} blocks starting with "${letter}"`);
+
+ for (const block of blocksToAdd) {
+ await buildPage.addBlock(block);
+ }
+
+ await buildPage.closeBlocksPanel();
+
+ // Verify blocks are visible
+ for (const block of blocksToAdd) {
+ await test.expect(buildPage.hasBlock(block)).resolves.toBeTruthy();
+ }
+
+ await buildPage.saveAgent(`blocks ${letter} test`, `testing blocks starting with ${letter}`);
+ }
+
// Reason Ignore: admonishment is in the wrong place visually with correct prettier rules
// prettier-ignore
- test("user can add a block", async () => { //(6)!
- await buildPage.closeTutorial(); //(9)!
+ test("user can add a block", async ({ page: _page }) => { //(6)!
await buildPage.openBlocksPanel(); //(10)!
const block = await buildPage.getDictionaryBlockDetails();
@@ -38,82 +84,108 @@ test.describe("Build", () => { //(1)!
});
// --8<-- [end:BuildPageExample]
- test.skip("user can add all blocks a-l", async ({ page }, testInfo) => {
- // this test is slow af so we 100x the timeout (sorry future me)
- test.setTimeout(testInfo.timeout * 100);
+ test("user can add blocks starting with a", async () => {
+ await addBlocksStartingWith("a");
+ });
- await buildPage.closeTutorial();
- await buildPage.openBlocksPanel();
- const blocks = await buildPage.getBlocks();
+ test("user can add blocks starting with b", async () => {
+ await addBlocksStartingWith("b");
+ });
- const blockIdsToSkip = await buildPage.getBlocksToSkip();
- const blockTypesToSkip = ["Input", "Output", "Agent", "AI"];
- console.log("⚠️ Skipping blocks:", blockIdsToSkip);
- console.log("⚠️ Skipping block types:", blockTypesToSkip);
+ test("user can add blocks starting with c", async () => {
+ await addBlocksStartingWith("c");
+ });
- // add all the blocks in order except for the agent executor block
- for (const block of blocks) {
- if (block.name[0].toLowerCase() >= "m") {
- continue;
- }
- if (!blockIdsToSkip.includes(block.id) && !blockTypesToSkip.includes(block.type)) {
- await buildPage.addBlock(block);
- }
- }
- await buildPage.closeBlocksPanel();
- // check that all the blocks are visible
- for (const block of blocks) {
- if (block.name[0].toLowerCase() >= "m") {
- continue;
- }
- if (!blockIdsToSkip.includes(block.id) && !blockTypesToSkip.includes(block.type)) {
- await test.expect(buildPage.hasBlock(block)).resolves.toBeTruthy();
- }
- }
+ test("user can add blocks starting with d", async () => {
+ await addBlocksStartingWith("d");
+ });
- // check that we can save the agent with all the blocks
- await buildPage.saveAgent("all blocks test", "all blocks test");
- // page should have a url like http://localhost:3000/build?flowID=f4f3a1da-cfb3-430f-a074-a455b047e340
- await test.expect(page).toHaveURL(({ searchParams }) => !!searchParams.get("flowID"));
+ test("user can add blocks starting with e", async () => {
+ await addBlocksStartingWith("e");
});
- test.skip("user can add all blocks m-z", async ({ page }, testInfo) => {
- // this test is slow af so we 100x the timeout (sorry future me)
- test.setTimeout(testInfo.timeout * 100);
+ test("user can add blocks starting with f", async () => {
+ await addBlocksStartingWith("f");
+ });
- await buildPage.closeTutorial();
- await buildPage.openBlocksPanel();
- const blocks = await buildPage.getBlocks();
+ test("user can add blocks starting with g", async () => {
+ await addBlocksStartingWith("g");
+ });
- const blockIdsToSkip = await buildPage.getBlocksToSkip();
- const blockTypesToSkip = ["Input", "Output", "Agent", "AI"];
- console.log("⚠️ Skipping blocks:", blockIdsToSkip);
- console.log("⚠️ Skipping block types:", blockTypesToSkip);
+ test("user can add blocks starting with h", async () => {
+ await addBlocksStartingWith("h");
+ });
- // add all the blocks in order except for the agent executor block
- for (const block of blocks) {
- if (block.name[0].toLowerCase() < "m") {
- continue;
- }
- if (!blockIdsToSkip.includes(block.id) && !blockTypesToSkip.includes(block.type)) {
- await buildPage.addBlock(block);
- }
- }
- await buildPage.closeBlocksPanel();
- // check that all the blocks are visible
- for (const block of blocks) {
- if (block.name[0].toLowerCase() < "m") {
- continue;
- }
- if (!blockIdsToSkip.includes(block.id) && !blockTypesToSkip.includes(block.type)) {
- await test.expect(buildPage.hasBlock(block)).resolves.toBeTruthy();
- }
- }
+ test("user can add blocks starting with i", async () => {
+ await addBlocksStartingWith("i");
+ });
- // check that we can save the agent with all the blocks
- await buildPage.saveAgent("all blocks test", "all blocks test");
- // page should have a url like http://localhost:3000/build?flowID=f4f3a1da-cfb3-430f-a074-a455b047e340
- await test.expect(page).toHaveURL(({ searchParams }) => !!searchParams.get("flowID"));
+ test("user can add blocks starting with j", async () => {
+ await addBlocksStartingWith("j");
+ });
+
+ test("user can add blocks starting with k", async () => {
+ await addBlocksStartingWith("k");
+ });
+
+ test("user can add blocks starting with l", async () => {
+ await addBlocksStartingWith("l");
+ });
+
+ test("user can add blocks starting with m", async () => {
+ await addBlocksStartingWith("m");
+ });
+
+ test("user can add blocks starting with n", async () => {
+ await addBlocksStartingWith("n");
+ });
+
+ test("user can add blocks starting with o", async () => {
+ await addBlocksStartingWith("o");
+ });
+
+ test("user can add blocks starting with p", async () => {
+ await addBlocksStartingWith("p");
+ });
+
+ test("user can add blocks starting with q", async () => {
+ await addBlocksStartingWith("q");
+ });
+
+ test("user can add blocks starting with r", async () => {
+ await addBlocksStartingWith("r");
+ });
+
+ test("user can add blocks starting with s", async () => {
+ await addBlocksStartingWith("s");
+ });
+
+ test("user can add blocks starting with t", async () => {
+ await addBlocksStartingWith("t");
+ });
+
+ test("user can add blocks starting with u", async () => {
+ await addBlocksStartingWith("u");
+ });
+
+ test("user can add blocks starting with v", async () => {
+ await addBlocksStartingWith("v");
+ });
+
+ test("user can add blocks starting with w", async () => {
+ await addBlocksStartingWith("w");
+ });
+
+ test("user can add blocks starting with x", async () => {
+ await addBlocksStartingWith("x");
+ });
+
+ test("user can add blocks starting with y", async () => {
+ await addBlocksStartingWith("y");
+ });
+
+ test("user can add blocks starting with z", async () => {
+ await addBlocksStartingWith("z");
});
test("build navigation is accessible from navbar", async ({ page }) => {
@@ -124,16 +196,13 @@ test.describe("Build", () => { //(1)!
await buildPage.navbar.clickBuildLink();
await buildPage.waitForPageLoad();
- await test.expect(page).toHaveURL("/build");
+ await hasUrl(page, "/build");
await test.expect(buildPage.isLoaded()).resolves.toBeTruthy();
});
- test("user can add two blocks and connect them", async ({
- page,
- }, testInfo) => {
+ test("user can add two blocks and connect them", async ({ page }, testInfo) => {
test.setTimeout(testInfo.timeout * 10);
- await buildPage.closeTutorial();
await buildPage.openBlocksPanel();
// Define the blocks to add
@@ -194,38 +263,38 @@ test.describe("Build", () => { //(1)!
.resolves.toBeTruthy();
});
- test("user can build an agent with inputs and output blocks", async ({
- page,
- }) => {
- // simple calculator to double input and output it
+ test("user can build an agent with inputs and output blocks", async ({ page }, testInfo) => {
+ test.setTimeout(testInfo.timeout * 20);
// prep
- await buildPage.closeTutorial();
await buildPage.openBlocksPanel();
- // find the blocks we want
- const blocks = await buildPage.getBlocks();
- const inputBlock = blocks.find((b) => b.name === "Agent Input");
- const outputBlock = blocks.find((b) => b.name === "Agent Output");
- const calculatorBlock = blocks.find((b) => b.name === "Calculator");
- if (!inputBlock || !outputBlock || !calculatorBlock) {
- throw new Error("Input or output block not found");
- }
-
- // add the blocks
+ // Get input block from Input category
+ const inputBlocks = await buildPage.getBlocksForCategory("Input");
+ const inputBlock = inputBlocks.find((b) => b.name === "Agent Input");
+ if (!inputBlock) throw new Error("Input block not found");
await buildPage.addBlock(inputBlock);
+
+ // Get output block from Output category
+ const outputBlocks = await buildPage.getBlocksForCategory("Output");
+ const outputBlock = outputBlocks.find((b) => b.name === "Agent Output");
+ if (!outputBlock) throw new Error("Output block not found");
await buildPage.addBlock(outputBlock);
+
+ // Get calculator block from Logic category
+ const logicBlocks = await buildPage.getBlocksForCategory("Logic");
+ const calculatorBlock = logicBlocks.find((b) => b.name === "Calculator");
+ if (!calculatorBlock) throw new Error("Calculator block not found");
await buildPage.addBlock(calculatorBlock);
+
await buildPage.closeBlocksPanel();
// Wait for blocks to be fully loaded
await page.waitForTimeout(1000);
- await test.expect(buildPage.hasBlock(inputBlock)).resolves.toBeTruthy();
- await test.expect(buildPage.hasBlock(outputBlock)).resolves.toBeTruthy();
- await test
- .expect(buildPage.hasBlock(calculatorBlock))
- .resolves.toBeTruthy();
+ await buildPage.hasBlock(inputBlock)
+ await buildPage.hasBlock(outputBlock)
+ await buildPage.hasBlock(calculatorBlock)
// Wait for blocks to be ready for connections
await page.waitForTimeout(1000);
diff --git a/autogpt_platform/frontend/src/tests/fixtures/index.ts b/autogpt_platform/frontend/src/tests/fixtures/index.ts
deleted file mode 100644
index ccab09cabd..0000000000
--- a/autogpt_platform/frontend/src/tests/fixtures/index.ts
+++ /dev/null
@@ -1,109 +0,0 @@
-/* eslint-disable react-hooks/rules-of-hooks */
-import { test as base } from "@playwright/test";
-import { createClient, SupabaseClient } from "@supabase/supabase-js";
-import { faker } from "@faker-js/faker";
-import fs from "fs";
-import path from "path";
-import { TestUser } from "./test-user.fixture";
-import { LoginPage } from "../pages/login.page";
-
-// Extend both worker state and test-specific fixtures
-type WorkerFixtures = {
- workerAuth: TestUser;
-};
-
-type TestFixtures = {
- testUser: TestUser;
- loginPage: LoginPage;
-};
-
-let supabase: SupabaseClient;
-
-function getSupabaseAdmin() {
- if (!supabase) {
- supabase = createClient(
- process.env.SUPABASE_URL!,
- process.env.SUPABASE_SERVICE_ROLE_KEY!,
- {
- auth: {
- autoRefreshToken: false,
- persistSession: false,
- },
- },
- );
- }
- return supabase;
-}
-
-export const test = base.extend<TestFixtures, WorkerFixtures>({
- // Define the worker-level fixture that creates and manages worker-specific auth
- workerAuth: [
- async ({}, use, workerInfo) => {
- const workerId = workerInfo.workerIndex;
- const fileName = path.resolve(
- process.cwd(),
- `.auth/worker-${workerId}.json`,
- );
-
- // Create directory if it doesn't exist
- const dirPath = path.dirname(fileName);
- if (!fs.existsSync(dirPath)) {
- fs.mkdirSync(dirPath, { recursive: true });
- }
-
- let auth: TestUser;
- if (fs.existsSync(fileName)) {
- auth = JSON.parse(fs.readFileSync(fileName, "utf-8"));
- } else {
- // Generate new worker-specific test user
- auth = {
- email: `test.worker.${workerId}.${Date.now()}@example.com`,
- password: faker.internet.password({ length: 12 }),
- };
-
- const supabase = getSupabaseAdmin();
- const {
- data: { user },
- error: signUpError,
- } = await supabase.auth.signUp({
- email: auth.email,
- password: auth.password,
- });
-
- if (signUpError) {
- throw signUpError;
- }
-
- auth.id = user?.id;
- fs.writeFileSync(fileName, JSON.stringify(auth));
- }
-
- await use(auth);
-
- // Cleanup code is commented out to preserve test users during development
- /*
- if (workerInfo.project.metadata.teardown) {
- if (auth.id) {
- await deleteTestUser(auth.id);
- }
- if (fs.existsSync(fileName)) {
- fs.unlinkSync(fileName);
- }
- }
- */
- },
- { scope: "worker" },
- ],
-
- // Define the test-level fixture that provides access to the worker auth
- testUser: async ({ workerAuth }, use) => {
- await use(workerAuth);
- },
-
- // Update login page fixture to use worker auth by default
- loginPage: async ({ page }, use) => {
- await use(new LoginPage(page));
- },
-});
-
-export { expect } from "@playwright/test";
diff --git a/autogpt_platform/frontend/src/tests/fixtures/login-page.fixture.ts b/autogpt_platform/frontend/src/tests/fixtures/login-page.fixture.ts
deleted file mode 100644
index 2bf67c8464..0000000000
--- a/autogpt_platform/frontend/src/tests/fixtures/login-page.fixture.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-/* eslint-disable react-hooks/rules-of-hooks */
-import { test as base } from "@playwright/test";
-import { LoginPage } from "../pages/login.page";
-import { Page } from "@playwright/test";
-export const loginPageFixture = base.extend<{ loginPage: LoginPage }>({
- loginPage: async ({ page }, use) => {
- await use(new LoginPage(page));
- },
-});
-
-// Export just the fixture function
-export const createLoginPageFixture = async (
- { page }: { page: Page },
- use: (loginPage: LoginPage) => Promise<void>,
-) => {
- await use(new LoginPage(page));
-};
diff --git a/autogpt_platform/frontend/src/tests/fixtures/test-user.fixture.ts b/autogpt_platform/frontend/src/tests/fixtures/test-user.fixture.ts
deleted file mode 100644
index e2fc2a003e..0000000000
--- a/autogpt_platform/frontend/src/tests/fixtures/test-user.fixture.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-/* eslint-disable react-hooks/rules-of-hooks */
-export type TestUser = {
- email: string;
- password: string;
- id?: string;
-};
diff --git a/autogpt_platform/frontend/src/tests/global-setup.ts b/autogpt_platform/frontend/src/tests/global-setup.ts
index ac0f0ad1fd..0c5d74609c 100644
--- a/autogpt_platform/frontend/src/tests/global-setup.ts
+++ b/autogpt_platform/frontend/src/tests/global-setup.ts
@@ -20,7 +20,7 @@ async function globalSetup(config: FullConfig) {
}
// Create test users using signup page
- const numberOfUsers = (config.workers || 1) + 3; // workers + buffer
+ const numberOfUsers = (config.workers || 1) + 8; // workers + buffer
console.log(`👥 Creating ${numberOfUsers} test users via signup...`);
const users = await createTestUsers(numberOfUsers);
diff --git a/autogpt_platform/frontend/src/tests/monitor.spec.ts b/autogpt_platform/frontend/src/tests/monitor.spec.ts
index a7e588acf0..bc047f2ab5 100644
--- a/autogpt_platform/frontend/src/tests/monitor.spec.ts
+++ b/autogpt_platform/frontend/src/tests/monitor.spec.ts
@@ -1,126 +1,139 @@
-import { TestInfo } from "@playwright/test";
-import { test } from "./fixtures";
+import test, { expect, TestInfo } from "@playwright/test";
+
import { BuildPage } from "./pages/build.page";
import { MonitorPage } from "./pages/monitor.page";
import { v4 as uuidv4 } from "uuid";
import * as fs from "fs/promises";
import path from "path";
-// --8<-- [start:AttachAgentId]
-test.describe("Monitor", () => {
- let buildPage: BuildPage;
- let monitorPage: MonitorPage;
-
- test.beforeEach(async ({ page, loginPage, testUser }, testInfo: TestInfo) => {
- buildPage = new BuildPage(page);
- monitorPage = new MonitorPage(page);
-
- // Start each test with login using worker auth
- await page.goto("/login");
- await loginPage.login(testUser.email, testUser.password);
- await test.expect(page).toHaveURL("/marketplace");
-
- // add a test agent
- const basicBlock = await buildPage.getDictionaryBlockDetails();
- const id = uuidv4();
- await buildPage.createSingleBlockAgent(
- `test-agent-${id}`,
- `test-agent-description-${id}`,
- basicBlock,
- );
- await buildPage.runAgent();
- // await monitorPage.navbar.clickMonitorLink();
- await page.goto("/monitoring"); // Library link now points to /library
- await monitorPage.waitForPageLoad();
- await test.expect(monitorPage.isLoaded()).resolves.toBeTruthy();
- testInfo.attach("agent-id", { body: id });
- });
- // --8<-- [end:AttachAgentId]
-
- test.afterAll(async ({}) => {
- // clear out the downloads folder
- console.log(
- `clearing out the downloads folder ${monitorPage.downloadsFolder}`,
- );
-
- await fs.rm(`${monitorPage.downloadsFolder}/monitor`, {
- recursive: true,
- force: true,
- });
- });
+import { LoginPage } from "./pages/login.page";
+import { getTestUser } from "./utils/auth";
+import { hasUrl } from "./utils/assertion";
+import {
+ navigateToLibrary,
+ clickFirstAgent,
+ runAgent,
+ waitForAgentPageLoad,
+} from "./pages/library.page";
- test("user can view agents", async () => {
- const agents = await monitorPage.listAgents();
- // there should be at least one agent
- await test.expect(agents.length).toBeGreaterThan(0);
- });
+test.describe.configure({
+ mode: "parallel",
+ timeout: 30000,
+});
- test.skip("user can export and import agents", async ({
- page,
- }, testInfo: TestInfo) => {
- // --8<-- [start:ReadAgentId]
- if (testInfo.attachments.length === 0 || !testInfo.attachments[0].body) {
- throw new Error("No agent id attached to the test");
- }
- const testAttachName = testInfo.attachments[0].body.toString();
- // --8<-- [end:ReadAgentId]
- const agents = await monitorPage.listAgents();
-
- const downloadPromise = page.waitForEvent("download");
- const agent = agents.find(
- (a: any) => a.name === `test-agent-${testAttachName}`,
- );
- if (!agent) {
- throw new Error(`Agent ${testAttachName} not found`);
- }
- await monitorPage.exportToFile(agent);
- const download = await downloadPromise;
-
- // Wait for the download process to complete and save the downloaded file somewhere.
- await download.saveAs(
- `${monitorPage.downloadsFolder}/monitor/${download.suggestedFilename()}`,
- );
- console.log(`downloaded file to ${download.suggestedFilename()}`);
- await test.expect(download.suggestedFilename()).toBeDefined();
- // test-agent-uuid-v1.json
- await test.expect(download.suggestedFilename()).toContain("test-agent-");
- await test.expect(download.suggestedFilename()).toContain("v1.json");
-
- // import the agent
- const preImportAgents = await monitorPage.listAgents();
- const filesInFolder = await fs.readdir(
- `${monitorPage.downloadsFolder}/monitor`,
- );
- const importFile = filesInFolder.find((f) => f.includes(testAttachName));
- if (!importFile) {
- throw new Error(`No import file found for agent ${testAttachName}`);
- }
- const baseName = importFile.split(".")[0];
- await monitorPage.importFromFile(
- path.resolve(monitorPage.downloadsFolder, "monitor"),
- importFile,
- baseName + "-imported",
- );
-
- // You'll be dropped at the build page, so hit run and then go back to monitor
- await buildPage.runAgent();
- await monitorPage.navbar.clickMonitorLink();
- await monitorPage.waitForPageLoad();
-
- const postImportAgents = await monitorPage.listAgents();
- await test
- .expect(postImportAgents.length)
- .toBeGreaterThan(preImportAgents.length);
- console.log(`postImportAgents: ${JSON.stringify(postImportAgents)}`);
- const importedAgent = postImportAgents.find(
- (a: any) => a.name === `${baseName}-imported`,
- );
- await test.expect(importedAgent).toBeDefined();
- });
+test.beforeEach(async ({ page }, testInfo: TestInfo) => {
+ const loginPage = new LoginPage(page);
+ const testUser = await getTestUser();
+ const monitorPage = new MonitorPage(page);
+
+ // Start each test with login using worker auth
+ await page.goto("/login");
+ await loginPage.login(testUser.email, testUser.password);
+ await hasUrl(page, "/marketplace");
+
+ // Navigate to library and run the first agent
+ await navigateToLibrary(page);
+ await clickFirstAgent(page);
+ await waitForAgentPageLoad(page);
+ await runAgent(page);
- test("user can view runs", async () => {
- const runs = await monitorPage.listRuns();
- console.log(runs);
- // there should be at least one run
- await test.expect(runs.length).toBeGreaterThan(0);
+ // Navigate to monitoring page
+ await page.goto("/monitoring");
+ await monitorPage.waitForPageLoad();
+ await test.expect(monitorPage.isLoaded()).resolves.toBeTruthy();
+
+ // Generate a test ID for tracking
+ const id = uuidv4();
+ testInfo.attach("agent-id", { body: id });
+});
+
+test.afterAll(async () => {
+ // clear out the downloads folder
+ const downloadsFolder = process.cwd() + "/downloads";
+ console.log(`clearing out the downloads folder ${downloadsFolder}/monitor`);
+
+ await fs.rm(`${downloadsFolder}/monitor`, {
+ recursive: true,
+ force: true,
});
});
+
+test.skip("user can export and import agents", async ({
+ page,
+}, testInfo: TestInfo) => {
+ const monitorPage = new MonitorPage(page);
+ const buildPage = new BuildPage(page);
+
+ if (testInfo.attachments.length === 0 || !testInfo.attachments[0].body) {
+ throw new Error("No agent id attached to the test");
+ }
+
+ const testAttachName = testInfo.attachments[0].body.toString();
+ const agents = await monitorPage.listAgents();
+
+ const downloadPromise = page.waitForEvent("download");
+
+ const agent = agents.find(
+ (a: any) => a.name === `test-agent-${testAttachName}`,
+ );
+
+ if (!agent) throw new Error(`Agent ${testAttachName} not found`);
+
+ await monitorPage.exportToFile(agent);
+ const download = await downloadPromise;
+
+ // Wait for the download process to complete and save the downloaded file somewhere.
+ await download.saveAs(
+ `${monitorPage.downloadsFolder}/monitor/${download.suggestedFilename()}`,
+ );
+
+ console.log(`downloaded file to ${download.suggestedFilename()}`);
+
+ expect(download.suggestedFilename()).toBeDefined();
+ expect(download.suggestedFilename()).toContain("test-agent-");
+ expect(download.suggestedFilename()).toContain("v1.json");
+
+ // import the agent
+ const preImportAgents = await monitorPage.listAgents();
+
+ const filesInFolder = await fs.readdir(
+ `${monitorPage.downloadsFolder}/monitor`,
+ );
+
+ const importFile = filesInFolder.find((f) => f.includes(testAttachName));
+ if (!importFile) {
+ throw new Error(`No import file found for agent ${testAttachName}`);
+ }
+
+ const baseName = importFile.split(".")[0];
+
+ await monitorPage.importFromFile(
+ path.resolve(monitorPage.downloadsFolder, "monitor"),
+ importFile,
+ baseName + "-imported",
+ );
+
+ // You'll be dropped at the build page, so hit run and then go back to monitor
+ await buildPage.runAgent();
+ await monitorPage.navbar.clickMonitorLink();
+ await monitorPage.waitForPageLoad();
+
+ const postImportAgents = await monitorPage.listAgents();
+
+ expect(postImportAgents.length).toBeGreaterThan(preImportAgents.length);
+
+ console.log(`postImportAgents: ${JSON.stringify(postImportAgents)}`);
+
+ const importedAgent = postImportAgents.find(
+ (a: any) => a.name === `${baseName}-imported`,
+ );
+
+ expect(importedAgent).toBeDefined();
+});
+
+test("user can view runs and agents", async ({ page }) => {
+ const monitorPage = new MonitorPage(page);
+ // const runs = await monitorPage.listRuns();
+ const agents = await monitorPage.listAgents();
+
+ expect(agents.length).toBeGreaterThan(0);
+});
diff --git a/autogpt_platform/frontend/src/tests/pages/build.page.ts b/autogpt_platform/frontend/src/tests/pages/build.page.ts
index 02c9295ec5..0fa4029eda 100644
--- a/autogpt_platform/frontend/src/tests/pages/build.page.ts
+++ b/autogpt_platform/frontend/src/tests/pages/build.page.ts
@@ -1,5 +1,6 @@
-import { Locator, Page } from "@playwright/test";
+import { expect, Locator, Page } from "@playwright/test";
import { BasePage } from "./base.page";
+import { Block as APIBlock } from "../../lib/autogpt-server-api/types";
export interface Block {
id: string;
@@ -98,6 +99,34 @@ export class BuildPage extends BasePage {
}
}
+ async getBlocksFromAPI(): Promise<Block[]> {
+ console.log(`Getting blocks from API request`);
+
+ // Make direct API request using the page's request context
+ const response = await this.page.request.get(
+ "http://localhost:3000/api/proxy/api/blocks",
+ );
+ const apiBlocks: APIBlock[] = await response.json();
+
+ console.log(`Found ${apiBlocks.length} blocks from API`);
+
+ // Convert API blocks to test Block format
+ return apiBlocks.map((block) => ({
+ id: block.id,
+ name: block.name,
+ description: block.description,
+ type: block.uiType,
+ }));
+ }
+
+ async getFilteredBlocksFromAPI(
+ filterFn: (block: Block) => boolean,
+ ): Promise<Block[]> {
+ console.log(`Getting filtered blocks from API`);
+ const blocks = await this.getBlocksFromAPI();
+ return blocks.filter(filterFn);
+ }
+
async addBlock(block: Block): Promise<void> {
console.log(`Adding block ${block.name} (${block.id}) to agent`);
await this.page.getByTestId(`block-name-${block.id}`).click();
@@ -109,12 +138,8 @@ export class BuildPage extends BasePage {
}
async hasBlock(block: Block): Promise<boolean> {
- console.log(
- `Checking if block ${block.name} (${block.id}) is visible on page`,
- );
try {
- // Use both ID and name for most precise matching
- const node = this.page.locator(`[data-blockid="${block.id}"]`).first();
+ const node = this.page.getByTestId(block.id).first();
return await node.isVisible();
} catch (error) {
console.error("Error checking for block:", error);
@@ -148,6 +173,83 @@ export class BuildPage extends BasePage {
// }
}
+ async selectBlockCategory(category: string): Promise<void> {
+ console.log(`Selecting block category: ${category}`);
+ await this.page.getByText(category, { exact: true }).click();
+ // Wait for the blocks to load after category selection
+ await this.page.waitForTimeout(500);
+ }
+
+ async discoverCategories(): Promise<string[]> {
+ console.log("Discovering available block categories");
+
+ this.page.waitForTimeout(2000);
+
+ // Get all category buttons
+ const categoryButtons = await this.page
+ .getByTestId("blocks-category")
+ .all();
+
+ const categories: string[] = [];
+ for (const button of categoryButtons) {
+ const categoryName = await button.textContent();
+ if (categoryName && categoryName.trim() !== "All") {
+ categories.push(categoryName.trim());
+ }
+ }
+
+ console.log(`Found ${categories.length} categories:`, categories);
+ return categories;
+ }
+
+ async getBlocksForCategory(category: string): Promise<Block[]> {
+ console.log(`Getting blocks for category: ${category}`);
+
+ // Select the category first
+ await this.selectBlockCategory(category);
+
+ try {
+ const blockFinder = this.page.locator('[data-id^="block-card-"]');
+ await blockFinder.first().waitFor();
+ const blocks = await blockFinder.all();
+
+ console.log(`found ${blocks.length} blocks in category ${category}`);
+
+ const results = await Promise.all(
+ blocks.map(async (block) => {
+ try {
+ const fullId = (await block.getAttribute("data-id")) || "";
+ const id = fullId.replace("block-card-", "");
+ const nameElement = block.locator('[data-testid^="block-name-"]');
+ const descriptionElement = block.locator(
+ '[data-testid^="block-description-"]',
+ );
+
+ const name = (await nameElement.textContent()) || "";
+ const description = (await descriptionElement.textContent()) || "";
+ const type = (await nameElement.getAttribute("data-type")) || "";
+
+ return {
+ id,
+ name: name.trim(),
+ type: type.trim(),
+ description: description.trim(),
+ };
+ } catch (elementError) {
+ console.error("Error processing block:", elementError);
+ return null;
+ }
+ }),
+ );
+
+ // Filter out any null results from errors
+ return results.filter((block): block is Block => block !== null);
+ } catch (error) {
+ console.error(`Error getting blocks for category ${category}:`, error);
+ return [];
+ }
+ }
+
async _buildBlockSelector(blockId: string, dataId?: string): Promise<string> {
const selector = dataId
? `[data-id="${dataId}"] [data-blockid="${blockId}"]`
@@ -464,16 +566,16 @@ export class BuildPage extends BasePage {
await this.page.waitForSelector('[id="press-run-label"]');
}
- async getBlocksInAgent(): Promise<string[]> {
- throw new Error("Not Tested to be correct");
- console.log(`getting blocks in agent`);
+ async createDummyAgent() {
+ await this.closeTutorial();
+ await this.openBlocksPanel();
+ const block = await this.getDictionaryBlockDetails();
- const ids = await Promise.all(
- (await this.page.locator(".react-flow__node").all()).map(
- async (node) => await node.getAttribute("data-id"),
- ),
- );
+ await this.addBlock(block);
+ await this.closeBlocksPanel();
+ await expect(this.hasBlock(block)).resolves.toBeTruthy();
- return ids.filter((id): id is string => id !== null);
+ await this.saveAgent("Test Agent", "Test Description");
+ await expect(this.isRunButtonEnabled()).resolves.toBeTruthy();
}
}
diff --git a/autogpt_platform/frontend/src/tests/pages/header.page.ts b/autogpt_platform/frontend/src/tests/pages/header.page.ts
new file mode 100644
index 0000000000..25520608c8
--- /dev/null
+++ b/autogpt_platform/frontend/src/tests/pages/header.page.ts
@@ -0,0 +1,9 @@
+import { Locator, Page } from "@playwright/test";
+
+function getNotificationButton(page: Page): Locator {
+ return page.locator('button[title="Agent Activity"]');
+}
+
+export const headerTest = {
+ getNotificationButton,
+};
diff --git a/autogpt_platform/frontend/src/tests/pages/library.page.ts b/autogpt_platform/frontend/src/tests/pages/library.page.ts
new file mode 100644
index 0000000000..2f1334a132
--- /dev/null
+++ b/autogpt_platform/frontend/src/tests/pages/library.page.ts
@@ -0,0 +1,93 @@
+import { Locator, Page } from "@playwright/test";
+import { getSelectors } from "../utils/selectors";
+
+// Locator functions
+export function getLibraryTab(page: Page): Locator {
+ return page.locator('a[href="/library"]');
+}
+
+export function getAgentCards(page: Page): Locator {
+ return page.getByTestId("library-agent-card");
+}
+
+export function getNewRunButton(page: Page): Locator {
+ return page.getByRole("button", { name: "New run" });
+}
+
+export function getAgentTitle(page: Page): Locator {
+ return page.locator("h1").first();
+}
+
+// Action functions
+export async function navigateToLibrary(page: Page): Promise<void> {
+ await getLibraryTab(page).click();
+ await page.waitForURL(/.*\/library/);
+}
+
+export async function clickFirstAgent(page: Page): Promise<void> {
+ const firstAgent = getAgentCards(page).first();
+ await firstAgent.click();
+}
+
+export async function navigateToAgentByName(
+ page: Page,
+ agentName: string,
+): Promise<void> {
+ const agentCard = getAgentCards(page).filter({ hasText: agentName }).first();
+ await agentCard.click();
+}
+
+export async function clickRunButton(page: Page): Promise<void> {
+ const { getId, getButton } = getSelectors(page);
+ const runButton = getId("agent-run-button");
+ const runAgainButton = getButton("Run again");
+
+ if (await runButton.isVisible()) {
+ await runButton.click();
+ } else if (await runAgainButton.isVisible()) {
+ await runAgainButton.click();
+ } else {
+ throw new Error("Neither run button nor run again button is visible");
+ }
+}
+
+export async function clickNewRunButton(page: Page): Promise<void> {
+ await getNewRunButton(page).click();
+}
+
+export async function runAgent(page: Page): Promise<void> {
+ await clickRunButton(page);
+}
+
+export async function waitForAgentPageLoad(page: Page): Promise<void> {
+ await page.waitForURL(/.*\/library\/agents\/[^/]+/);
+ await page.waitForLoadState("networkidle");
+}
+
+export async function getAgentName(page: Page): Promise<string> {
+ return (await getAgentTitle(page).textContent()) || "";
+}
+
+export async function isLoaded(page: Page): Promise<boolean> {
+ return await page.locator("h1").isVisible();
+}
+
+export async function waitForRunToComplete(
+ page: Page,
+ timeout = 30000,
+): Promise<void> {
+ await page.waitForSelector(".bg-green-500, .bg-red-500, .bg-purple-500", {
+ timeout,
+ });
+}
+
+export async function getRunStatus(page: Page): Promise<string> {
+ if (await page.locator(".animate-spin").isVisible()) {
+ return "running";
+ } else if (await page.locator(".bg-green-500").isVisible()) {
+ return "completed";
+ } else if (await page.locator(".bg-red-500").isVisible()) {
+ return "failed";
+ }
+ return "unknown";
+}
diff --git a/autogpt_platform/frontend/src/tests/pages/monitor.page.ts b/autogpt_platform/frontend/src/tests/pages/monitor.page.ts
index 74aebe1000..1d89e9651f 100644
--- a/autogpt_platform/frontend/src/tests/pages/monitor.page.ts
+++ b/autogpt_platform/frontend/src/tests/pages/monitor.page.ts
@@ -120,7 +120,9 @@ export class MonitorPage extends BasePage {
async listRuns(filter?: Agent): Promise<Run[]> {
console.log(`listing runs`);
// Wait for the runs table to be loaded - look for table header "Agent"
- await this.page.locator("[data-testid='flow-runs-list-body']").waitFor();
+ await this.page.locator("[data-testid='flow-runs-list-body']").waitFor({
+ timeout: 10000,
+ });
// Get all run rows
const rows = await this.page
diff --git a/autogpt_platform/frontend/src/tests/profile.spec.ts b/autogpt_platform/frontend/src/tests/profile.spec.ts
index c2f644c113..c592b370ea 100644
--- a/autogpt_platform/frontend/src/tests/profile.spec.ts
+++ b/autogpt_platform/frontend/src/tests/profile.spec.ts
@@ -1,52 +1,47 @@
-import { test } from "./fixtures";
+import { LoginPage } from "./pages/login.page";
import { ProfilePage } from "./pages/profile.page";
+import test, { expect } from "@playwright/test";
+import { getTestUser } from "./utils/auth";
+import { hasUrl } from "./utils/assertion";
-test.describe("Profile", () => {
- let profilePage: ProfilePage;
-
- test.beforeEach(async ({ page, loginPage, testUser }) => {
- profilePage = new ProfilePage(page);
-
- // Start each test with login using worker auth
- await page.goto("/login");
- await loginPage.login(testUser.email, testUser.password);
- await test.expect(page).toHaveURL("/marketplace");
- });
-
- test("user can view their profile information", async ({ page }) => {
- await profilePage.navbar.clickProfileLink();
- // workaround for #8788
- // sleep for 10 seconds to allow page to load due to bug in our system
- await page.waitForTimeout(10_000);
- await page.reload();
- await page.reload();
- await test.expect(profilePage.isLoaded()).resolves.toBeTruthy();
- await test.expect(page).toHaveURL(new RegExp("/profile"));
-
- // Verify email matches test worker's email
- const displayedHandle = await profilePage.getDisplayedName();
- test.expect(displayedHandle).not.toBeNull();
- test.expect(displayedHandle).not.toBe("");
- test.expect(displayedHandle).toBeDefined();
- });
-
- test("profile navigation is accessible from navbar", async ({ page }) => {
- await profilePage.navbar.clickProfileLink();
- await test.expect(page).toHaveURL(new RegExp("/profile"));
- await test.expect(profilePage.isLoaded()).resolves.toBeTruthy();
- });
-
- test("profile displays user Credential providers", async () => {
- await profilePage.navbar.clickProfileLink();
-
- // await test
- // .expect(page.getByTestId("profile-section-personal"))
- // .toBeVisible();
- // await test
- // .expect(page.getByTestId("profile-section-settings"))
- // .toBeVisible();
- // await test
- // .expect(page.getByTestId("profile-section-security"))
- // .toBeVisible();
- });
+test.beforeEach(async ({ page }) => {
+ const loginPage = new LoginPage(page);
+ const testUser = await getTestUser();
+
+ await page.goto("/login");
+ await loginPage.login(testUser.email, testUser.password);
+ await hasUrl(page, "/marketplace");
+});
+
+test("user can view their profile information", async ({ page }) => {
+ const profilePage = new ProfilePage(page);
+
+ await profilePage.navbar.clickProfileLink();
+
+ // workaround for #8788
+ // sleep for 10 seconds to allow page to load due to bug in our system
+ await page.waitForTimeout(10000);
+ await page.reload();
+ await page.reload();
+ await expect(profilePage.isLoaded()).resolves.toBeTruthy();
+ await hasUrl(page, new RegExp("/profile"));
+
+ // Verify email matches test worker's email
+ const displayedHandle = await profilePage.getDisplayedName();
+ expect(displayedHandle).not.toBeNull();
+ expect(displayedHandle).not.toBe("");
+ expect(displayedHandle).toBeDefined();
+});
+
+test("profile navigation is accessible from navbar", async ({ page }) => {
+ const profilePage = new ProfilePage(page);
+
+ await profilePage.navbar.clickProfileLink();
+ await hasUrl(page, new RegExp("/profile"));
+ await expect(profilePage.isLoaded()).resolves.toBeTruthy();
+});
+
+test("profile displays user Credential providers", async ({ page }) => {
+ const profilePage = new ProfilePage(page);
+ await profilePage.navbar.clickProfileLink();
});
diff --git a/autogpt_platform/frontend/src/tests/signin.spec.ts b/autogpt_platform/frontend/src/tests/signin.spec.ts
index 60976cb488..d9bb5c796c 100644
--- a/autogpt_platform/frontend/src/tests/signin.spec.ts
+++ b/autogpt_platform/frontend/src/tests/signin.spec.ts
@@ -1,72 +1,73 @@
// auth.spec.ts
-import { test } from "./fixtures";
-
-test.describe("Authentication", () => {
- test("user can login successfully", async ({ page, loginPage, testUser }) => {
- await page.goto("/login");
- await loginPage.login(testUser.email, testUser.password);
- await test.expect(page).toHaveURL("/marketplace");
-
- const accountMenuBtn = page.getByTestId("profile-popout-menu-trigger");
-
- await test.expect(accountMenuBtn).toBeVisible();
-
- await accountMenuBtn.click();
-
- const dialog = page.getByRole("dialog");
- await test.expect(dialog).toBeVisible();
-
- const username = testUser.email.split("@")[0];
- await test.expect(dialog.getByText(username)).toBeVisible();
-
- const logoutBtn = page.getByRole("button", { name: "Log out" });
- await test.expect(logoutBtn).toBeVisible();
- await logoutBtn.click();
- });
-
- test("user can logout successfully", async ({
- page,
- loginPage,
- testUser,
- }) => {
- await page.goto("/login");
- await loginPage.login(testUser.email, testUser.password);
- await test.expect(page).toHaveURL("/marketplace");
-
- // Click on the profile menu trigger to open popout
- await page.getByTestId("profile-popout-menu-trigger").click();
-
- // Wait for menu to be visible before clicking logout
- await page.getByRole("button", { name: "Log out" }).waitFor({
- state: "visible",
- timeout: 5000,
- });
-
- // Click the logout button in the popout menu
- await page.getByRole("button", { name: "Log out" }).click();
-
- await test.expect(page).toHaveURL("/login");
- });
-
- test("login in, then out, then in again", async ({
- page,
- loginPage,
- testUser,
- }) => {
- await page.goto("/login");
- await loginPage.login(testUser.email, testUser.password);
- await test.expect(page).toHaveURL("/marketplace");
- // Click on the profile menu trigger to open popout
- await page.getByTestId("profile-popout-menu-trigger").click();
-
- // Click the logout button in the popout menu
- await page.getByRole("button", { name: "Log out" }).click();
-
- await test.expect(page).toHaveURL("/login");
- await loginPage.login(testUser.email, testUser.password);
- await test.expect(page).toHaveURL("/marketplace");
- await test
- .expect(page.getByTestId("profile-popout-menu-trigger"))
- .toBeVisible();
- });
+
+import test from "@playwright/test";
+import { getTestUser } from "./utils/auth";
+import { LoginPage } from "./pages/login.page";
+import { hasUrl, isVisible } from "./utils/assertion";
+import { getSelectors } from "./utils/selectors";
+
+test.beforeEach(async ({ page }) => {
+ await page.goto("/login");
+});
+
+test("user can login successfully", async ({ page }) => {
+ const testUser = await getTestUser();
+ const loginPage = new LoginPage(page);
+ const { getId, getButton, getText, getRole } = getSelectors(page);
+
+ await loginPage.login(testUser.email, testUser.password);
+ await hasUrl(page, "/marketplace");
+
+ const accountMenuTrigger = getId("profile-popout-menu-trigger");
+
+ await isVisible(accountMenuTrigger);
+
+ await accountMenuTrigger.click();
+ const accountMenuPopover = getRole("dialog");
+ await isVisible(accountMenuPopover);
+
+ const username = testUser.email.split("@")[0];
+ await isVisible(getText(username));
+
+ const logoutBtn = getButton("Log out");
+ await isVisible(logoutBtn);
+ await logoutBtn.click();
+});
+
+test("user can logout successfully", async ({ page }) => {
+ const testUser = await getTestUser();
+ const loginPage = new LoginPage(page);
+ const { getButton, getId } = getSelectors(page);
+
+ await loginPage.login(testUser.email, testUser.password);
+ await hasUrl(page, "/marketplace");
+
+ // Open account menu
+ await getId("profile-popout-menu-trigger").click();
+
+ // Logout
+ await getButton("Log out").click();
+ await hasUrl(page, "/login");
+});
+
+test("login in, then out, then in again", async ({ page }) => {
+ const testUser = await getTestUser();
+ const loginPage = new LoginPage(page);
+ const { getButton, getId } = getSelectors(page);
+
+ await loginPage.login(testUser.email, testUser.password);
+ await hasUrl(page, "/marketplace");
+
+ // Click on the profile menu trigger to open account menu
+ await getId("profile-popout-menu-trigger").click();
+
+ // Click the logout button in the popout menu
+ await getButton("Log out").click();
+
+ await test.expect(page).toHaveURL("/login");
+ await loginPage.login(testUser.email, testUser.password);
+ await test.expect(page).toHaveURL("/marketplace");
+ await test
+ .expect(page.getByTestId("profile-popout-menu-trigger"))
+ .toBeVisible();
});
diff --git a/autogpt_platform/frontend/src/tests/signup.spec.ts b/autogpt_platform/frontend/src/tests/signup.spec.ts
index f561649819..0d94c9b93f 100644
--- a/autogpt_platform/frontend/src/tests/signup.spec.ts
+++ b/autogpt_platform/frontend/src/tests/signup.spec.ts
@@ -1,133 +1,126 @@
-import { expect, test } from "./fixtures";
+import test, { expect } from "@playwright/test";
import {
generateTestEmail,
generateTestPassword,
signupTestUser,
validateSignupForm,
} from "./utils/signup";
+import { getSelectors } from "./utils/selectors";
+import { hasUrl, isVisible } from "./utils/assertion";
+
+test("user can signup successfully", async ({ page }) => {
+ try {
+ const testUser = await signupTestUser(page);
+ const { getText, getId } = getSelectors(page);
+
+ // Verify user was created
+ expect(testUser.email).toBeTruthy();
+ expect(testUser.password).toBeTruthy();
+ expect(testUser.createdAt).toBeTruthy();
+
+ const marketplaceText = getText(
+ "Bringing you AI agents designed by thinkers from around the world",
+ );
+
+ // Verify we're on marketplace and authenticated
+ await hasUrl(page, "/marketplace");
+ await isVisible(marketplaceText);
+ await isVisible(getId("profile-popout-menu-trigger"));
+ } catch (error) {
+ console.error("❌ Signup test failed:", error);
+ }
+});
-test.describe("Signup Flow", () => {
- test("user can signup successfully", async ({ page }) => {
- console.log("🧪 Testing user signup flow...");
-
- try {
- const testUser = await signupTestUser(page);
-
- // Verify user was created
- expect(testUser.email).toBeTruthy();
- expect(testUser.password).toBeTruthy();
- expect(testUser.createdAt).toBeTruthy();
-
- // Verify we're on marketplace and authenticated
- await expect(page).toHaveURL("/marketplace");
- await expect(
- page.getByText(
- "Bringing you AI agents designed by thinkers from around the world",
- ),
- ).toBeVisible();
- await expect(
- page.getByTestId("profile-popout-menu-trigger"),
- ).toBeVisible();
-
- console.log(`✅ User successfully signed up: ${testUser.email}`);
- } catch (error) {
- console.error("❌ Signup test failed:", error);
- }
- });
+test("signup form validation works", async ({ page }) => {
+ const { getField, getRole, getButton } = getSelectors(page);
+ const emailInput = getField("Email");
+ const passwordInput = page.locator("#password");
+ const confirmPasswordInput = page.locator("#confirmPassword");
+ const signupButton = getButton("Sign up");
+ const termsCheckbox = getRole("checkbox");
- test("signup form validation works", async ({ page }) => {
- console.log("🧪 Testing signup form validation...");
+ await validateSignupForm(page);
- await validateSignupForm(page);
+ // Additional validation tests
+ await page.goto("/signup");
- // Additional validation tests
- await page.goto("/signup");
+ // Test with mismatched passwords
+ await emailInput.fill(generateTestEmail());
+ await passwordInput.fill("password1");
+ await confirmPasswordInput.fill("password2");
+ await termsCheckbox.click();
+ await signupButton.click();
- // Test with mismatched passwords
- console.log("❌ Testing mismatched passwords...");
- await page.getByLabel("Email").fill(generateTestEmail());
- const passwordInput = page.getByLabel("Password", { exact: true });
- const confirmPasswordInput = page.getByLabel("Confirm Password", {
- exact: true,
- });
- await passwordInput.fill("password1");
- await confirmPasswordInput.fill("password2");
- await page.getByRole("checkbox").click();
- await page.getByRole("button", { name: "Sign up" }).click();
+ // Should still be on signup page
+ await hasUrl(page, /\/signup/);
+});
- // Should still be on signup page
- await expect(page).toHaveURL(/\/signup/);
- console.log("✅ Mismatched passwords correctly blocked");
- });
+test("user can signup with custom credentials", async ({ page }) => {
+ const { getId } = getSelectors(page);
- test("user can signup with custom credentials", async ({ page }) => {
- console.log("🧪 Testing signup with custom credentials...");
+ try {
+ const customEmail = generateTestEmail();
+ const customPassword = generateTestPassword();
- try {
- const customEmail = generateTestEmail();
- const customPassword = generateTestPassword();
+ const testUser = await signupTestUser(page, customEmail, customPassword);
- const testUser = await signupTestUser(page, customEmail, customPassword);
+ // Verify correct credentials were used
+ expect(testUser.email).toBe(customEmail);
+ expect(testUser.password).toBe(customPassword);
- // Verify correct credentials were used
- expect(testUser.email).toBe(customEmail);
- expect(testUser.password).toBe(customPassword);
+ // Verify successful signup
+ await hasUrl(page, "/marketplace");
+ await isVisible(getId("profile-popout-menu-trigger"));
+ } catch (error) {
+ console.error("❌ Custom credentials signup test failed:", error);
+ }
+});
- // Verify successful signup
- await expect(page).toHaveURL("/marketplace");
- await expect(
- page.getByTestId("profile-popout-menu-trigger"),
- ).toBeVisible();
+test("user can signup with existing email handling", async ({
+ page,
+ browser,
+}) => {
+ try {
+ const testEmail = generateTestEmail();
+ const testPassword = generateTestPassword();
- console.log(`✅ Custom credentials signup worked: ${testUser.email}`);
- } catch (error) {
- console.error("❌ Custom credentials signup test failed:", error);
- }
- });
+ // First signup
+ const firstUser = await signupTestUser(page, testEmail, testPassword);
+ expect(firstUser.email).toBe(testEmail);
- test("user can signup with existing email handling", async ({
- page,
- browser,
- }) => {
- console.log("🧪 Testing duplicate email handling...");
+ // Create new browser context for second signup (simulates new browser window)
+ const newContext = await browser.newContext();
+ const newPage = await newContext.newPage();
try {
- const testEmail = generateTestEmail();
- const testPassword = generateTestPassword();
-
- // First signup
- console.log(`👤 First signup attempt: ${testEmail}`);
- const firstUser = await signupTestUser(page, testEmail, testPassword);
-
- expect(firstUser.email).toBe(testEmail);
- console.log("✅ First signup successful");
-
- // Create new browser context for second signup (simulates new browser window)
- console.log("🔄 Creating new browser context...");
- const newContext = await browser.newContext();
- const newPage = await newContext.newPage();
-
- try {
- // Second signup attempt with same email in new browser context
- console.log(
- `👤 Second signup attempt in new browser context: ${testEmail}`,
- );
- await signupTestUser(newPage, testEmail, testPassword);
- expect(
- newPage.getByText("User with this email already exists"),
- ).toBeVisible();
- console.log("ℹ️ Second signup handled gracefully");
- } catch (_error) {
- console.log("ℹ️ Second signup rejected as expected");
- } finally {
- // Clean up new browser context
- await newContext.close();
- console.log("🧹 New browser context closed");
- }
-
- console.log("✅ Duplicate email handling test completed");
- } catch (error) {
- console.error("❌ Duplicate email handling test failed:", error);
+ const { getText, getField, getRole, getButton } = getSelectors(newPage);
+
+ // Second signup attempt with same email in new browser context
+ // Navigate to signup page
+ await newPage.goto("http://localhost:3000/signup");
+
+ // Wait for page to load
+ getText("Create a new account");
+
+ // Fill form
+ const emailInput = getField("Email");
+ await emailInput.fill(testEmail);
+ const passwordInput = newPage.locator("#password");
+ await passwordInput.fill(testPassword);
+ const confirmPasswordInput = newPage.locator("#confirmPassword");
+ await confirmPasswordInput.fill(testPassword);
+
+ // Agree to terms and submit
+ await getRole("checkbox").click();
+ const signupButton = getButton("Sign up");
+ await signupButton.click();
+ await isVisible(getText("User with this email already exists"));
+ } catch (_error) {
+ } finally {
+ // Clean up new browser context
+ await newContext.close();
}
- });
+ } catch (error) {
+ console.error("❌ Duplicate email handling test failed:", error);
+ }
});
diff --git a/autogpt_platform/frontend/src/tests/title.spec.ts b/autogpt_platform/frontend/src/tests/title.spec.ts
index 46933ccb28..08bade66b4 100644
--- a/autogpt_platform/frontend/src/tests/title.spec.ts
+++ b/autogpt_platform/frontend/src/tests/title.spec.ts
@@ -1,8 +1,6 @@
-import { test, expect } from "./fixtures";
+import test, { expect } from "@playwright/test";
test("has title", async ({ page }) => {
await page.goto("/");
-
- // Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/AutoGPT Platform/);
});
diff --git a/autogpt_platform/frontend/src/tests/util.spec.ts b/autogpt_platform/frontend/src/tests/util.spec.ts
index ddf26b4e5c..acf4cf53ec 100644
--- a/autogpt_platform/frontend/src/tests/util.spec.ts
+++ b/autogpt_platform/frontend/src/tests/util.spec.ts
@@ -1,4 +1,4 @@
-import { test, expect } from "./fixtures";
+import test, { expect } from "@playwright/test";
import { setNestedProperty } from "../lib/utils";
const testCases = [
@@ -34,74 +34,64 @@ const testCases = [
},
];
-// Test Suite
-test.describe("Nested Property Setter Tests", () => {
- test.describe("Valid Usage Tests", () => {
- // Test secure implementation
- for (const { name, path, value, expected } of testCases) {
- test(name, () => {
- const obj = {};
- setNestedProperty(obj, path, value);
- expect(obj).toEqual(expected);
- });
- }
+for (const { name, path, value, expected } of testCases) {
+ test(name, () => {
+ const obj = {};
+ setNestedProperty(obj, path, value);
+ expect(obj).toEqual(expected);
});
+}
- test.describe("Security Improvements", () => {
- test("should throw error for null object", () => {
- expect(() => {
- setNestedProperty(null, "test", "value");
- }).toThrow("Target must be a non-null object");
- });
+test("should throw error for null object", () => {
+ expect(() => {
+ setNestedProperty(null, "test", "value");
+ }).toThrow("Target must be a non-null object");
+});
- test("should throw error for undefined object", () => {
- expect(() => {
- setNestedProperty(undefined, "test", "value");
- }).toThrow("Target must be a non-null object");
- });
+test("should throw error for undefined object", () => {
+ expect(() => {
+ setNestedProperty(undefined, "test", "value");
+ }).toThrow("Target must be a non-null object");
+});
- test("should throw error for non-object target", () => {
- expect(() => {
- setNestedProperty("string", "test", "value");
- }).toThrow("Target must be a non-null object");
- });
+test("should throw error for non-object target", () => {
+ expect(() => {
+ setNestedProperty("string", "test", "value");
+ }).toThrow("Target must be a non-null object");
+});
- test("should throw error for empty path", () => {
- expect(() => {
- setNestedProperty({}, "", "value");
- }).toThrow("Path must be a non-empty string");
- });
+test("should throw error for empty path", () => {
+ expect(() => {
+ setNestedProperty({}, "", "value");
+ }).toThrow("Path must be a non-empty string");
+});
- test("should throw error for __proto__ access", () => {
- expect(() => {
- setNestedProperty({}, "__proto__.malicious", "attack");
- }).toThrow("Invalid property name: __proto__");
- });
+test("should throw error for __proto__ access", () => {
+ expect(() => {
+ setNestedProperty({}, "__proto__.malicious", "attack");
+ }).toThrow("Invalid property name: __proto__");
+});
- test("should throw error for constructor access", () => {
- expect(() => {
- setNestedProperty({}, "constructor.prototype.malicious", "attack");
- }).toThrow("Invalid property name: constructor");
- });
+test("should throw error for constructor access", () => {
+ expect(() => {
+ setNestedProperty({}, "constructor.prototype.malicious", "attack");
+ }).toThrow("Invalid property name: constructor");
+});
- test("should throw error for prototype access", () => {
- expect(() => {
- setNestedProperty({}, "obj.prototype.malicious", "attack");
- }).toThrow("Invalid property name: prototype");
- });
- });
+test("should throw error for prototype access", () => {
+ expect(() => {
+ setNestedProperty({}, "obj.prototype.malicious", "attack");
+ }).toThrow("Invalid property name: prototype");
+});
- test.describe("Prototype Pollution Vulnerability Demo", () => {
- test("secure implementation prevents prototype pollution", () => {
- const obj = {};
- expect(() => {
- setNestedProperty(obj, "__proto__.polluted", true);
- }).toThrow("Invalid property name: __proto__");
+test("secure implementation prevents prototype pollution", () => {
+ const obj = {};
+ expect(() => {
+ setNestedProperty(obj, "__proto__.polluted", true);
+ }).toThrow("Invalid property name: __proto__");
- // Verify no pollution occurred
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-ignore
- expect({}.polluted).toBeUndefined();
- });
- });
+ // Verify no pollution occurred
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ // @ts-ignore
+ expect({}.polluted).toBeUndefined();
});
diff --git a/autogpt_platform/frontend/src/tests/utils/assertion.ts b/autogpt_platform/frontend/src/tests/utils/assertion.ts
new file mode 100644
index 0000000000..1141727d66
--- /dev/null
+++ b/autogpt_platform/frontend/src/tests/utils/assertion.ts
@@ -0,0 +1,45 @@
+import { Locator, Page, expect } from "@playwright/test";
+
+export async function isVisible(el: Locator, timeout?: number) {
+ await expect(el).toBeVisible(timeout ? { timeout } : undefined);
+}
+
+export async function hasAttribute(
+ el: Locator,
+ label: string,
+ val: string | RegExp,
+) {
+ await expect(el).toHaveAttribute(label, val);
+}
+
+export async function hasTextContent(el: Locator, text: string) {
+ await expect(el).toContainText(text);
+}
+
+export async function isHidden(el: Locator, timeout?: number) {
+ await expect(el).toBeHidden(timeout ? { timeout } : undefined);
+}
+
+export async function hasUrl(
+ page: Page,
+ url: string | RegExp,
+ opts?: { decoded?: boolean },
+) {
+ if (opts?.decoded) {
+ return expect(decodeURIComponent(page.url())).toBe(url);
+ }
+
+ await expect(page).toHaveURL(url);
+}
+
+export async function hasFieldValue(el: Locator, value: string | RegExp) {
+ await expect(el).toHaveValue(value);
+}
+
+export async function isDisabled(el: Locator) {
+ await expect(el).toBeDisabled();
+}
+
+export async function isEnabled(el: Locator) {
+ await expect(el).toBeEnabled();
+}
diff --git a/autogpt_platform/frontend/src/tests/utils/auth.ts b/autogpt_platform/frontend/src/tests/utils/auth.ts
index ed0aba4818..775dc31559 100644
--- a/autogpt_platform/frontend/src/tests/utils/auth.ts
+++ b/autogpt_platform/frontend/src/tests/utils/auth.ts
@@ -17,16 +17,6 @@ export interface UserPool {
version: string;
}
-// Using Playwright MCP server tools for browser automation
-// No need to manage browser instances manually
-
-/**
- * Create a new test user through signup page using Playwright MCP server
- * @param email - User email (optional, will generate if not provided)
- * @param password - User password (optional, will generate if not provided)
- * @param ignoreOnboarding - Skip onboarding and go to marketplace (default: true)
- * @returns Promise<TestUser> - Created user object
- */
export async function createTestUser(
email?: string,
password?: string,
@@ -52,6 +42,7 @@ export async function createTestUser(
userEmail,
userPassword,
ignoreOnboarding,
+ true,
);
return testUser;
} finally {
@@ -65,11 +56,6 @@ export async function createTestUser(
}
}
-/**
- * Create multiple test users
- * @param count - Number of users to create
- * @returns Promise<TestUser[]> - Array of created users
- */
export async function createTestUsers(count: number): Promise<TestUser[]> {
console.log(`👥 Creating ${count} test users...`);
@@ -90,11 +76,6 @@ export async function createTestUsers(count: number): Promise<TestUser[]> {
return users;
}
-/**
- * Save user pool to file system
- * @param users - Array of users to save
- * @param filePath - Path to save the file (optional)
- */
export async function saveUserPool(
users: TestUser[],
filePath?: string,
@@ -123,11 +104,6 @@ export async function saveUserPool(
}
}
-/**
- * Load user pool from file system
- * @param filePath - Path to load from (optional)
- * @returns Promise<UserPool | null> - Loaded user pool or null if not found
- */
export async function loadUserPool(
filePath?: string,
): Promise<UserPool | null> {
@@ -158,27 +134,17 @@ export async function loadUserPool(
}
}
-/**
- * Clean up all test users from a pool
- * Note: When using signup page method, cleanup removes the user pool file
- * @param filePath - Path to load from (optional)
- */
-export async function cleanupTestUsers(filePath?: string): Promise<void> {
- const defaultPath = path.resolve(process.cwd(), ".auth", "user-pool.json");
- const finalPath = filePath || defaultPath;
-
- console.log(`🧹 Cleaning up test users...`);
+export async function getTestUser(): Promise<TestUser> {
+ const userPool = await loadUserPool();
+ if (!userPool) {
+ throw new Error("User pool not found");
+ }
- try {
- if (fs.existsSync(finalPath)) {
- fs.unlinkSync(finalPath);
- console.log(`✅ Deleted user pool file: ${finalPath}`);
- } else {
- console.log(`⚠️ No user pool file found to cleanup`);
- }
- } catch (error) {
- console.error(`❌ Failed to cleanup user pool:`, error);
+ if (userPool.users.length === 0) {
+ throw new Error("No users available in the pool");
}
- console.log(`🎉 Cleanup completed`);
+ // Return a random user from the pool
+ const randomIndex = Math.floor(Math.random() * userPool.users.length);
+ return userPool.users[randomIndex];
}
diff --git a/autogpt_platform/frontend/src/tests/utils/selectors.ts b/autogpt_platform/frontend/src/tests/utils/selectors.ts
new file mode 100644
index 0000000000..4306be5178
--- /dev/null
+++ b/autogpt_platform/frontend/src/tests/utils/selectors.ts
@@ -0,0 +1,67 @@
+import { Locator, Page } from "@playwright/test";
+
+export function getSelectors(page: Page) {
+ return {
+ getButton: makeSelector(page, getButton),
+ getText: (name: string | RegExp, options?: GetByTextOptions) =>
+ getText(page, name, options),
+ getLink: makeSelector(page, getLink),
+ getField: makeSelector(page, getField),
+ getId: makeSelector(page, getId),
+ within: (name: string) => within(page, name),
+ getRole: (
+ role: Roles,
+ name?: string | RegExp,
+ options?: GetByRoleOptions & { within?: Locator },
+ ) => getRole(options?.within || page, role, name, options),
+ };
+}
+
+function makeSelector(
+ page: Page,
+ fn: (context: Page | Locator, name: string | RegExp) => Locator,
+) {
+ return <T extends string | RegExp>(name: T, locator?: Locator) =>
+ fn(locator || page, name);
+}
+
+function getText(
+ context: Page | Locator,
+ name: string | RegExp,
+ options?: GetByTextOptions,
+) {
+ return context.getByText(name, options);
+}
+
+function getButton(context: Page | Locator, name: string | RegExp) {
+ return getRole(context, "button", name);
+}
+
+function getLink(context: Page | Locator, name: string | RegExp) {
+ return context.getByRole("link", { name });
+}
+
+function getField(context: Page | Locator, name: string | RegExp) {
+ return context.getByLabel(name, { exact: true });
+}
+
+function getId(context: Page | Locator, testid: string | RegExp) {
+ return context.getByTestId(testid);
+}
+
+function within(context: Page, testid: string) {
+ return context.locator(`data-testid=${testid}`);
+}
+
+function getRole(
+ context: Page | Locator,
+ role: Roles,
+ name?: string | RegExp,
+ options?: GetByRoleOptions,
+) {
+ return context.getByRole(role, { ...options, ...(name ? { name } : null) });
+}
+
+type GetByTextOptions = Parameters<Page["getByText"]>["1"];
+type GetByRoleOptions = Parameters<Page["getByRole"]>["1"];
+type Roles = Parameters<Page["getByRole"]>["0"];
diff --git a/autogpt_platform/frontend/src/tests/utils/signin.ts b/autogpt_platform/frontend/src/tests/utils/signin.ts
index 9ba7debbef..b9c77ede79 100644
--- a/autogpt_platform/frontend/src/tests/utils/signin.ts
+++ b/autogpt_platform/frontend/src/tests/utils/signin.ts
@@ -1,6 +1,11 @@
import { Page } from "@playwright/test";
import { LoginPage } from "../pages/login.page";
-import { TestUser } from "../fixtures/test-user.fixture";
+
+type TestUser = {
+ email: string;
+ password: string;
+ id?: string;
+};
/**
* Utility functions for signin/authentication tests
diff --git a/autogpt_platform/frontend/src/tests/utils/signup.ts b/autogpt_platform/frontend/src/tests/utils/signup.ts
index 232c017dd8..ab8e8be0b1 100644
--- a/autogpt_platform/frontend/src/tests/utils/signup.ts
+++ b/autogpt_platform/frontend/src/tests/utils/signup.ts
@@ -1,32 +1,30 @@
import { faker } from "@faker-js/faker";
import { TestUser } from "./auth";
+import { getSelectors } from "./selectors";
+import { isVisible } from "./assertion";
+import { BuildPage } from "../pages/build.page";
-/**
- * Create a test user through signup page for test setup
- * @param page - Playwright page object
- * @param email - User email (optional, will generate if not provided)
- * @param password - User password (optional, will generate if not provided)
- * @param ignoreOnboarding - Skip onboarding and go to marketplace (default: true)
- * @returns Promise<TestUser> - Created user object
- */
export async function signupTestUser(
page: any,
email?: string,
password?: string,
ignoreOnboarding: boolean = true,
+ withAgent: boolean = false,
): Promise<TestUser> {
const userEmail = email || faker.internet.email();
const userPassword = password || faker.internet.password({ length: 12 });
+ const { getText, getField, getRole, getButton, getId } = getSelectors(page);
+
try {
// Navigate to signup page
await page.goto("http://localhost:3000/signup");
// Wait for page to load
- await page.getByText("Create a new account");
+ getText("Create a new account");
// Fill form
- const emailInput = page.getByLabel("Email");
+ const emailInput = getField("Email");
await emailInput.fill(userEmail);
const passwordInput = page.locator("#password");
await passwordInput.fill(userPassword);
@@ -34,8 +32,8 @@ export async function signupTestUser(
await confirmPasswordInput.fill(userPassword);
// Agree to terms and submit
- await page.getByRole("checkbox").click();
- const signupButton = page.getByRole("button", { name: "Sign up" });
+ await getRole("checkbox").click();
+ const signupButton = getButton("Sign up");
await signupButton.click();
// Wait for successful signup - could redirect to onboarding or marketplace
@@ -77,6 +75,18 @@ export async function signupTestUser(
.waitFor({ state: "visible", timeout: 10000 });
}
+ if (withAgent) {
+ // Create a dummy agent for each new user
+ const buildLink = getId("navbar-link-build");
+ await buildLink.click();
+
+ const blocksBtn = getId("blocks-control-blocks-button");
+ await isVisible(blocksBtn);
+
+ const buildPage = new BuildPage(page);
+ await buildPage.createDummyAgent();
+ }
+
const testUser: TestUser = {
email: userEmail,
password: userPassword,
@@ -90,13 +100,6 @@ export async function signupTestUser(
}
}
-/**
- * Complete signup and navigate to marketplace
- * @param page - Playwright page object from MCP server
- * @param email - User email (optional, will generate if not provided)
- * @param password - User password (optional, will generate if not provided)
- * @returns Promise<TestUser> - Created user object
- */
export async function signupAndNavigateToMarketplace(
page: any,
email?: string,
@@ -111,11 +114,6 @@ export async function signupAndNavigateToMarketplace(
return testUser;
}
-/**
- * Validate signup form behavior
- * @param page - Playwright page object from MCP server
- * @returns Promise<void>
- */
export async function validateSignupForm(page: any): Promise<void> {
console.log("🧪 Validating signup form...");
@@ -150,18 +148,10 @@ export async function validateSignupForm(page: any): Promise<void> {
console.log("✅ Signup form validation completed");
}
-/**
- * Generate unique test email
- * @returns string - Unique test email
- */
export function generateTestEmail(): string {
return `test.${Date.now()}.${Math.random().toString(36).substring(7)}@example.com`;
}
-/**
- * Generate secure test password
- * @returns string - Secure test password
- */
export function generateTestPassword(): string {
return faker.internet.password({ length: 12 });
}
diff --git a/autogpt_platform/frontend/src/tests/utils/user-generator.ts b/autogpt_platform/frontend/src/tests/utils/user-generator.ts
deleted file mode 100644
index 83baa6bcab..0000000000
--- a/autogpt_platform/frontend/src/tests/utils/user-generator.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-import { faker } from "@faker-js/faker";
-import { TestUser } from "./auth";
-
-/**
- * Generate a test user with random data
- * @param options - Optional parameters to override defaults
- * @returns TestUser object with generated data
- */
-export function generateUser(options?: {
- email?: string;
- password?: string;
- name?: string;
-}): TestUser {
- console.log("🎲 Generating test user...");
-
- const user: TestUser = {
- email: options?.email || faker.internet.email(),
- password: options?.password || faker.internet.password({ length: 12 }),
- createdAt: new Date().toISOString(),
- };
-
- console.log(`✅ Generated user: ${user.email}`);
- return user;
-}
-
-/**
- * Generate multiple test users
- * @param count - Number of users to generate
- * @returns Array of TestUser objects
- */
-export function generateUsers(count: number): TestUser[] {
- console.log(`👥 Generating ${count} test users...`);
-
- const users: TestUser[] = [];
-
- for (let i = 0; i < count; i++) {
- users.push(generateUser());
- }
-
- console.log(`✅ Generated ${users.length} test users`);
- return users;
-}