TestingBot & Stagehand
Stagehand is an AI Browser Automation Framework that allows you to create and manage browser automation tasks using AI. It is available in both NodeJS and Python.
By connecting Stagehand to TestingBot's remote browser grid, you can run multiple AI-driven browser automation tasks in parallel, without the need to manage the browsers yourself. Each session is video recorded and available for replay in the TestingBot dashboard. You can run browsers from various geographical locations and use different browser versions, on multiple operating systems.
Connecting to a remote browser
To get started, please install these packages:
- Install the Stagehand library:
@browserbasehq/stagehand
- Install the TestingBot library:
npm install testingbot-api
We can now run a simple example. This will connect Stagehand with a remote TestingBot browser session. Use the AI prompt to test a specific scenario, by describing what you want to test in your own natural language.
const { Stagehand } = require("@browserbasehq/stagehand");
const TestingBot = require("testingbot-api");
(async () => {
const tb = new TestingBot({
api_key: process.env.TESTINGBOT_KEY,
api_secret: process.env.TESTINGBOT_SECRET
});
const options = {
capabilities: {
browserName: 'chrome',
browserVersion: 'latest',
platform: 'WIN11'
}
};
const session = await tb.createSession(options);
const stagehand = new Stagehand({
env: "LOCAL",
localBrowserLaunchOptions: {
cdpUrl: session['cdp_url']
}
});
await stagehand.init();
const page = stagehand.page;
await page.goto("https://testingbot.com/pricing");
const extractResult = await page.extract("Extract the pricing plans from this page");
console.log(`Extract result:\n`, extractResult);
})();
Make sure to replace TESTINGBOT_KEY
and TESTINGBOT_SECRET
with your actual TestingBot API key and secret.
In the example above, we create a new TestingBot session with the desired capabilities. We then pass the cdpUrl
to Stagehand, which allows it to connect to the remote browser session on TestingBot.
You can now use Stagehand's AI capabilities to interact with the page, extract information, or perform other actions as needed.
For more information on using Stagehand, please refer to the Stagehand documentation.