From 69d5cef4d3b7aa36a116e3dcd6a53dcbecf2cb92 Mon Sep 17 00:00:00 2001 From: Anirudh Kamath Date: Sat, 21 Dec 2024 20:08:42 -0800 Subject: [PATCH] fix e2e --- evals/deterministic/stagehand.config.ts | 4 ++-- evals/deterministic/tests/contexts.test.ts | 9 ++++++--- lib/StagehandPage.ts | 11 +++++++++-- lib/index.ts | 4 ++-- package.json | 3 ++- types/page.ts | 2 +- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/evals/deterministic/stagehand.config.ts b/evals/deterministic/stagehand.config.ts index 62406a27..87adf9c4 100644 --- a/evals/deterministic/stagehand.config.ts +++ b/evals/deterministic/stagehand.config.ts @@ -2,8 +2,8 @@ import type { ConstructorParams, LogLine } from "../../lib"; const StagehandConfig: ConstructorParams = { env: "BROWSERBASE" /* Environment to run Stagehand in */, - apiKey: process.env.BROWSERBASE_API_KEY /* API key for authentication */, - projectId: process.env.BROWSERBASE_PROJECT_ID /* Project identifier */, + apiKey: process.env.BROWSERBASE_API_KEY! /* API key for authentication */, + projectId: process.env.BROWSERBASE_PROJECT_ID! /* Project identifier */, verbose: 1 /* Logging verbosity level (0=quiet, 1=normal, 2=verbose) */, debugDom: true /* Enable DOM debugging features */, headless: false /* Run browser in headless mode */, diff --git a/evals/deterministic/tests/contexts.test.ts b/evals/deterministic/tests/contexts.test.ts index 26afef98..7662a8aa 100644 --- a/evals/deterministic/tests/contexts.test.ts +++ b/evals/deterministic/tests/contexts.test.ts @@ -5,8 +5,11 @@ import StagehandConfig from "../stagehand.config"; // Configuration const CONTEXT_TEST_URL = "https://docs.browserbase.com"; -const BROWSERBASE_PROJECT_ID = process.env["BROWSERBASE_PROJECT_ID"]!; -const BROWSERBASE_API_KEY = process.env["BROWSERBASE_API_KEY"]!; +const BROWSERBASE_PROJECT_ID = process.env.BROWSERBASE_PROJECT_ID!; +const BROWSERBASE_API_KEY = process.env.BROWSERBASE_API_KEY!; + +console.log("BROWSERBASE_PROJECT_ID", BROWSERBASE_PROJECT_ID); +console.log("BROWSERBASE_API_KEY", BROWSERBASE_API_KEY); const bb = new Browserbase({ apiKey: BROWSERBASE_API_KEY, @@ -62,7 +65,7 @@ async function setRandomCookie(contextId: string, stagehand: Stagehand) { } test.describe("Contexts", () => { - test("Persists and re-uses a context", async () => { + test.only("Persists and re-uses a context", async () => { let contextId: string; let testCookieName: string; let testCookieValue: string; diff --git a/lib/StagehandPage.ts b/lib/StagehandPage.ts index 4ce8f823..966ee11c 100644 --- a/lib/StagehandPage.ts +++ b/lib/StagehandPage.ts @@ -6,10 +6,11 @@ import { LLMClient } from "./llm/LLMClient"; import { ActOptions, ActResult, GotoOptions, Stagehand } from "./index"; import { StagehandActHandler } from "./handlers/actHandler"; import { StagehandContext } from "./StagehandContext"; +import { Page } from "../types/page"; export class StagehandPage { private stagehand: Stagehand; - private intPage: PlaywrightPage; + private intPage: Page; private intContext: StagehandContext; private actHandler: StagehandActHandler; private llmClient: LLMClient; @@ -56,6 +57,12 @@ export class StagehandPage { return result; }; + if (prop === "act") { + return async (options: ActOptions) => { + return this.act(options); + }; + } + return target[prop as keyof PlaywrightPage]; }, }); @@ -63,7 +70,7 @@ export class StagehandPage { return this; } - public get page(): PlaywrightPage { + public get page(): Page { return this.intPage; } diff --git a/lib/index.ts b/lib/index.ts index 2efeaacb..33b98996 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -58,7 +58,7 @@ async function getBrowser( "BROWSERBASE_API_KEY is required to use BROWSERBASE env. Defaulting to LOCAL.", level: 0, }); - this.env = "LOCAL"; + env = "LOCAL"; } if (!projectId) { logger({ @@ -390,7 +390,7 @@ export class Stagehand { } public get env(): "LOCAL" | "BROWSERBASE" { - if (this.intEnv === "BROWSERBASE" && this.browserbaseSessionID) { + if (this.intEnv === "BROWSERBASE" && this.apiKey && this.projectId) { return "BROWSERBASE"; } return "LOCAL"; diff --git a/package.json b/package.json index e0eeaee7..9941326a 100644 --- a/package.json +++ b/package.json @@ -81,5 +81,6 @@ "bugs": { "url": "https://github.com/browserbase/stagehand/issues" }, - "homepage": "https://github.com/browserbase/stagehand#readme" + "homepage": "https://github.com/browserbase/stagehand#readme", + "packageManager": "pnpm@9.15.0+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c" } diff --git a/types/page.ts b/types/page.ts index 96bcd6ff..8fc1d714 100644 --- a/types/page.ts +++ b/types/page.ts @@ -3,5 +3,5 @@ import { ActResult } from "./act"; import { ActOptions } from "./stagehand"; export interface Page extends PlaywrightPage { - act: (options: ActOptions) => Promise; + act?: (options: ActOptions) => Promise; }