Skip to content

Commit

Permalink
fix e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
kamath committed Dec 22, 2024
1 parent b4aa507 commit 69d5cef
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
4 changes: 2 additions & 2 deletions evals/deterministic/stagehand.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */,
Expand Down
9 changes: 6 additions & 3 deletions evals/deterministic/tests/contexts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions lib/StagehandPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,14 +57,20 @@ export class StagehandPage {
return result;
};

if (prop === "act") {
return async (options: ActOptions) => {
return this.act(options);
};
}

return target[prop as keyof PlaywrightPage];
},
});
await this._waitForSettledDom();
return this;
}

public get page(): PlaywrightPage {
public get page(): Page {
return this.intPage;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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";
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c"
}
2 changes: 1 addition & 1 deletion types/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { ActResult } from "./act";
import { ActOptions } from "./stagehand";

export interface Page extends PlaywrightPage {
act: (options: ActOptions) => Promise<ActResult>;
act?: (options: ActOptions) => Promise<ActResult>;
}

0 comments on commit 69d5cef

Please sign in to comment.