Launch Your First Browser Session
This guide walks you through setting up your TestMu AI account, creating your first browser session on TestMu AI Browser Cloud, and driving it using TypeScript/Puppeteer. In just a few minutes, you'll be programmatically controlling a cloud browser.
Prerequisites
Step 1: Sign up on TestMu AI
Step 2: Get your credentials:
- After signing up, navigate to Settings → Account Settings
- Find your Username and Access Key
Step 3: Set up environment variables:
- Create a
.envfile in your project root (if you don't have one) - Add your credentials:
LT_USERNAME=your_username
LT_ACCESS_KEY=your_access_key
Make sure to add
.envto your.gitignorefile to keep your credentials secure.
Installing the TestMu AI Browser SDK
npm i @testmuai/browser-cloud
Requirements: Node.js 16+ (Node 18+ required if using the Playwright adapter)
Create Your First Session
Let's create a simple script that launches a cloud browser, navigates to a page, and cleans up:
- Puppeteer
- Playwright
- Selenium
// my-first-session.ts
import { Browser } from '@testmuai/browser-cloud';
const client = new Browser();
async function main() {
const session = await client.sessions.create({
adapter: 'puppeteer',
lambdatestOptions: {
build: 'Getting Started',
name: 'My First Session',
'LT:Options': {
username: process.env.LT_USERNAME,
accessKey: process.env.LT_ACCESS_KEY,
}
}
});
console.log('Session created:', session.id);
console.log('View live session at:', session.sessionViewerUrl);
// Connect and use the browser
const browser = await client.puppeteer.connect(session);
const page = (await browser.pages())[0];
await page.goto('https://example.com');
console.log('Title:', await page.title());
// Clean up
await browser.close();
await client.sessions.release(session.id);
console.log('Session released');
}
main().catch(console.error);
note
Playwright requires Node.js 18+.
// my-first-session.ts
import { Browser } from '@testmuai/browser-cloud';
const client = new Browser();
async function main() {
const session = await client.sessions.create({
adapter: 'playwright',
lambdatestOptions: {
build: 'Getting Started',
name: 'My First Session',
'LT:Options': {
username: process.env.LT_USERNAME,
accessKey: process.env.LT_ACCESS_KEY,
}
}
});
console.log('Session created:', session.id);
console.log('View live session at:', session.sessionViewerUrl);
// Connect and use the browser
const { browser, context, page } = await client.playwright.connect(session);
await page.goto('https://example.com');
console.log('Title:', await page.title());
// Clean up
await browser.close();
await client.sessions.release(session.id);
console.log('Session released');
}
main().catch(console.error);
// my-first-session.ts
import { Browser } from '@testmuai/browser-cloud';
const client = new Browser();
async function main() {
const session = await client.sessions.create({
adapter: 'selenium',
lambdatestOptions: {
build: 'Getting Started',
name: 'My First Session',
'LT:Options': {
username: process.env.LT_USERNAME,
accessKey: process.env.LT_ACCESS_KEY,
}
}
});
console.log('Session created:', session.id);
console.log('View live session at:', session.sessionViewerUrl);
// Connect and use the browser
const driver = await client.selenium.connect(session);
await driver.get('https://example.com');
console.log('Title:', await driver.getTitle());
// Clean up
await driver.quit();
await client.sessions.release(session.id);
console.log('Session released');
}
main().catch(console.error);
