๐ 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
Step 2: Get Your API Key
- Visit BrowserTest Dashboard
- Sign up for an account
- Navigate to API Keys section
- 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?
Take Screenshots
Learn about different screenshot types and options.
Agentic Testing
Run tests with natural language instructions.
Batch Operations
Process multiple operations efficiently.
Error Handling
Handle errors and edge cases properly.
๐ Need Help?
Join our Community
Ask questions and get help from the community.