Skip to main content

Overview

TestDriver sandboxes can be customized to match your testing requirements. Install applications, configure system settings, and prepare environments programmatically to ensure your tests run in the right context.

Provisioning API

The provisioning API allows you to customize sandbox environments before running tests.

Installing Applications

Use the provisioning API to install software packages:
import { ai } from '@testdriverai/sdk';

// Install applications before tests
await ai('install Chrome browser');
await ai('install Node.js version 18');
await ai('install PostgreSQL database');

System Configuration

Configure system settings and preferences:
// Set environment variables
await ai('set NODE_ENV to production');

// Configure system settings
await ai('enable dark mode');
await ai('set screen resolution to 1920x1080');

Exec Command

The exec command allows you to run shell commands directly in the sandbox:
import { exec } from '@testdriverai/sdk';

// Install packages via package manager
await exec('apt-get update && apt-get install -y git');

// Run setup scripts
await exec('npm install -g typescript');

// Configure applications
await exec('cp config.json /etc/myapp/config.json');

Examples

Installing Development Tools

// Install common development tools
await exec('apt-get update');
await exec('apt-get install -y curl wget git vim');

Setting Up a Web Server

// Install and configure nginx
await exec('apt-get install -y nginx');
await exec('systemctl start nginx');
await exec('systemctl enable nginx');

Installing Language Runtimes

// Install Python and pip
await exec('apt-get install -y python3 python3-pip');
await exec('pip3 install requests pytest');

Pre-Test Setup

Run setup commands before each test:
import { beforeAll } from 'vitest';

beforeAll(async () => {
  // Install dependencies
  await exec('npm install');
  
  // Start services
  await exec('npm run start-server &');
  
  // Wait for service to be ready
  await ai('wait for server to start on port 3000');
});

Environment Templates

Create reusable environment configurations:
// environments/chrome-dev.js
export async function setupChromeDev() {
  await exec('apt-get update');
  await exec('apt-get install -y google-chrome-stable');
  await exec('npm install -g lighthouse');
}

// Use in tests
import { setupChromeDev } from './environments/chrome-dev';

beforeAll(async () => {
  await setupChromeDev();
});

Custom VM Images (Enterprise)

For more complex customization needs, Enterprise customers can work with TestDriver to create custom VM images.

Benefits of Custom AMIs

  • Faster Startup: Pre-installed applications ready to use
  • Consistency: Identical environments across all test runs
  • Complex Setup: Handle intricate installation procedures once
  • Version Control: Track and manage environment changes

What Can Be Pre-Installed

  • Desktop applications (browsers, IDEs, etc.)
  • System dependencies and libraries
  • Language runtimes and frameworks
  • Database servers and tools
  • Custom certificates and credentials
  • System configurations and settings

Working with TestDriver

Enterprise customers receive dedicated support for custom environments:
  1. Requirements Gathering: Discuss your environment needs
  2. AMI Development: We build and test the custom image
  3. Validation: Review and approve the environment
  4. Deployment: Roll out to your test infrastructure
  5. Maintenance: Regular updates and security patches
Learn more about custom environments in our Enterprise documentation.

Best Practices

Keep Setup Scripts Fast

  • Pre-install large dependencies in custom AMIs when possible
  • Cache downloaded files and packages
  • Run setup in parallel when independent

Make Setup Idempotent

  • Check if software is already installed before installing
  • Use version checks to avoid unnecessary reinstalls
  • Handle errors gracefully
async function ensureNodeInstalled() {
  try {
    await exec('node --version');
  } catch {
    await exec('curl -fsSL https://deb.nodesource.com/setup_18.x | bash -');
    await exec('apt-get install -y nodejs');
  }
}

Version Lock Dependencies

  • Specify exact versions of tools and packages
  • Avoid “latest” tags that can change
  • Document version requirements
// Good - specific version
await exec('npm install -g [email protected]');

// Avoid - version may change
await exec('npm install -g typescript');

Troubleshooting

Installation Failures

Check logs for detailed error messages:
try {
  await exec('apt-get install -y mypackage');
} catch (error) {
  console.error('Installation failed:', error);
}

Permission Issues

Some commands may require sudo:
await exec('sudo apt-get update');

Network Issues

Ensure your sandbox has internet access for downloads:
// Test connectivity
await exec('ping -c 3 google.com');

Learn More