Skip to content

Commit

Permalink
test error occurs without API key or LLM client
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcguire12 committed Jan 7, 2025
1 parent 65197f3 commit 02f8bb2
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions evals/deterministic/tests/Errors/apiKeyError.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { test, expect } from "@playwright/test";
import { Stagehand } from "../../../../lib";
import StagehandConfig from "../../stagehand.config";
import { z } from "zod";

test.describe("API key/LLMClient error", () => {
test("Should confirm that we get an error if we call extract without LLM API key or LLMClient", async () => {
const stagehand = new Stagehand(StagehandConfig);
await stagehand.init();
await stagehand.page.goto("https://docs.browserbase.com/introduction");

let errorThrown: Error | null = null;

try {
await stagehand.page.extract({
instruction:
"From the introduction page, extract the explanation of what Browserbase is.",
schema: z.object({
stars: z.string().describe("the explanation of what Browserbase is"),
}),
});
} catch (error) {
errorThrown = error as Error;
}

expect(errorThrown).toBeInstanceOf(Error);
expect(errorThrown?.message).toContain(
"No LLM API key or LLM Client configured",
);

await stagehand.close();
});

test("Should confirm that we get an error if we call act without LLM API key or LLMClient", async () => {
const stagehand = new Stagehand(StagehandConfig);
await stagehand.init();
await stagehand.page.goto("https://docs.browserbase.com/introduction");

let errorThrown: Error | null = null;

try {
await stagehand.page.act({
action: "Click on the 'Quickstart' section",
});
} catch (error) {
errorThrown = error as Error;
}

expect(errorThrown).toBeInstanceOf(Error);
expect(errorThrown?.message).toContain(
"No LLM API key or LLM Client configured",
);

await stagehand.close();
});

test("Should confirm that we get an error if we call observe without LLM API key or LLMClient", async () => {
const stagehand = new Stagehand(StagehandConfig);
await stagehand.init();
await stagehand.page.goto("https://docs.browserbase.com/introduction");

let errorThrown: Error | null = null;

try {
await stagehand.page.observe();
} catch (error) {
errorThrown = error as Error;
}

expect(errorThrown).toBeInstanceOf(Error);
expect(errorThrown?.message).toContain(
"No LLM API key or LLM Client configured",
);

await stagehand.close();
});
});

0 comments on commit 02f8bb2

Please sign in to comment.