Skip to main content

Overview

The TestDriver client is the main entry point for the SDK. It handles authentication, sandbox connection, and provides access to all testing methods.

Constructor

Parameters

string
required
Your TestDriver API key from the dashboard
object
Configuration options for the client

Example

Authentication

auth()

Authenticate with the TestDriver API.
Returns: Promise<string> - Authentication token Example:
You must call auth() before connect(). Most examples call both sequentially.

Connection Management

connect()

Connect to a sandbox environment. This creates or reconnects to a virtual machine where your tests will run.

Parameters

object
Connection options
Returns: Promise&lt;Object&gt; - Sandbox instance details including instanceId, ip, vncPort, etc.

Examples

Basic connection:
Reconnect to existing sandbox:
Self-hosted sandbox:

disconnect()

Disconnect from the sandbox and clean up resources.
Returns: Promise<void> Example:

Instance Information

getInstance()

Get the current sandbox instance details.
Returns: Object | null - Sandbox instance information Example:

getSessionId()

Get the current session ID for tracking and debugging.
Returns: string | null - Session ID Example:

Logging & Events

setLogging()

Enable or disable console logging at runtime.
Parameters:
  • enabled (boolean) - Whether to enable logging
Example:

getEmitter()

Get the event emitter for custom event handling.
Returns: EventEmitter2 - Event emitter instance Example:

Complete Example

Best Practices

Use beforeAll/afterAll to create one sandbox per test suite rather than per test. This significantly reduces execution time.
Wrap connect() in a try-catch block to handle network issues or quota limits:
Use afterAll or try-finally blocks to ensure disconnect() is called even if tests fail. This prevents orphaned sandboxes.
Never hardcode API keys. The SDK automatically loads TD_API_KEY from your .env file:
.env