Skip to main content
Run end-to-end browser tests in consistent, isolated cloud environments. Browserbase gives you reliable infrastructure for automated testing workflows, whether you’re using Stagehand or Playwright.
  • Reduce flaky tests with predictable, isolated browser sessions
  • Debug failures with built-in session recordings and screenshots
  • Scale test runs across concurrent sessions without managing infrastructure
  • Test from different locations and viewports with proxies and configurable browser settings

Template

Get started quickly with a ready-to-use testing template.

Website Link Tester

Clone, configure, and run in minutes

Example: Testing a login flow

To demonstrate automated testing with Browserbase, this example validates a login flow against a sample application.

Code example

import { Stagehand } from "@browserbasehq/stagehand";
import { z } from "zod";
import dotenv from "dotenv";

async function main() {
    dotenv.config();
    // initialize stagehand
    const stagehand = new Stagehand({
        env: "BROWSERBASE",
    });
    await stagehand.init();
    const page = stagehand.context.pages()[0];

    async function automatedLoginTest(inputs: any) {
        // Navigate to the form
        await page.goto("https://www.saucedemo.com/");

        await stagehand.act(`Input Username: ${inputs.username}`);
        await stagehand.act(`Input Password: ${inputs.password}`);
        await stagehand.act("Click Login Button");

        // take a screenshot of the page
        await page.screenshot({ path: "login_screenshot.png" });

        // log the url
        return page.url();
    }

    const response = await automatedLoginTest({
        username: "standard_user",
        password: "secret_sauce",
    });
    console.log(response);

    // close the stagehand session
    await stagehand.close();
}

main().catch(console.error);

Configuration options

Set up a consistent environment

Test in a predictable environment with the same Chrome version every time.
SDK
// Create a standardized session
const session = await bb.sessions.create({
  // Optional: Configure viewport size (desktop, mobile)
  browserSettings: {
    viewport: {
      width: 1280,
      height: 720
    }
  }
});

Test from different locations

Test how your app behaves from different locations:
SDK
// Create a session with proxy support
const session = await bb.sessions.create({
  proxies: [
      {
      type: "browserbase",
      geolocation: {
          city: "New York",
          state: "NY",
          country: "US"
          }
      }
  ]
});

Complete configuration options

Set the viewport, operating system, and full list of configuration options to customize your test environment.

Best practices

Record sessions

Every session is automatically recorded and available in the Browserbase dashboard. With Session Recording, you can watch the exact session execution to debug failures efficiently.
console.log(`View session recording at https://browserbase.com/sessions/${session.id}`);
No extra setup required—session recording happens automatically, allowing you to diagnose flaky tests and failures with ease.

Use metadata to organize tests

Add metadata for easier organization:
SDK
const session = await bb.sessions.create({
  userMetadata: {
      testName: "login_flow",
      suite: "authentication"
  }
});

Capture screenshots

Capture screenshots at critical points for easier debugging.
// Take a screenshot
await page.screenshot({ path: "login_screenshot.png" });

Next steps

Session Inspector

Learn how to use the Session Inspector to debug test failures

Session Metadata

Organize and query your test sessions effectively

Proxies

Test your application from different geographic locations

Screenshots and PDFs

Capture visual evidence during test execution