Skip to main content

๐Ÿš€ Get Started in 3 Steps

Get up and running with BrowserTest SDK in just a few minutes.

Step 1: Install the SDK

npm install browsertest-sdk
yarn add browsertest-sdk
pnpm add browsertest-sdk

Step 2: Get Your API Key

  1. Visit BrowserTest Dashboard
  2. Sign up for an account
  3. Navigate to API Keys section
  4. Create a new API key
Keep your API key secure and never commit it to version control. Use environment variables instead.

Step 3: Write Your First Code

import { BrowserTest } from 'browsertest-sdk';

// Initialize the SDK
const bt = new BrowserTest({
  apiKey: process.env.BROWSERTEST_API_KEY // Use environment variable
});

// Take your first screenshot
async function main() {
  try {
    const screenshot = await bt.screenshot.take({
      url: 'https://example.com',
      fullPage: true,
      format: 'png'
    });

    console.log('Screenshot captured!');
    console.log('Size:', screenshot.data.screenshot.length, 'bytes');
    console.log('Dimensions:', `${screenshot.data.width}x${screenshot.data.height}`);

  } catch (error) {
    console.error('Error:', error.message);
  }
}

main();

๐Ÿงช Test Your Setup

Run this test script to verify everything works:
import { BrowserTest } from 'browsertest-sdk';

const bt = new BrowserTest({
  apiKey: process.env.BROWSERTEST_API_KEY
});

async function testConnection() {
  try {
    // Test connection
    const isConnected = await bt.testConnection();
    console.log('API Connection:', isConnected ? 'โœ… OK' : 'โŒ Failed');

    // Check usage
    const usage = await bt.getUsage();
    console.log('Plan:', usage.plan);
    console.log('Screenshots remaining:', usage.usage.screenshot.remaining);
    console.log('Tests remaining:', usage.usage.agentic.remaining);

  } catch (error) {
    console.error('Setup test failed:', error.message);
  }
}

testConnection();

๐Ÿ“ Project Structure

For a typical project, organize your code like this:
your-project/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ””โ”€โ”€ browserTest.js     # SDK wrapper/service
โ”‚   โ”œโ”€โ”€ tests/
โ”‚   โ”‚   โ”œโ”€โ”€ visual-regression.js
โ”‚   โ”‚   โ””โ”€โ”€ e2e-tests.js
โ”‚   โ””โ”€โ”€ utils/
โ”‚       โ””โ”€โ”€ screenshot-helpers.js
โ”œโ”€โ”€ .env                       # API key (don't commit!)
โ””โ”€โ”€ package.json

๐Ÿ”ง Configuration

Create a service wrapper for easy usage throughout your app:
// src/services/browserTest.js
import { BrowserTest } from 'browsertest-sdk';

const bt = new BrowserTest({
  apiKey: process.env.BROWSERTEST_API_KEY,
  timeout: 30000,
  retries: 3
});

export default bt;

๐ŸŽฏ What Next?

๐Ÿ†˜ Need Help?

Join our Community

Ask questions and get help from the community.