-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test error occurs without API key or LLM client
- Loading branch information
1 parent
65197f3
commit 02f8bb2
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |