Overview
TheTestDriver client is the main entry point for the SDK. It handles authentication, sandbox connection, and provides access to all testing methods.
Constructor
Parameters
Configuration options for the client
Example
Authentication
auth()
Authenticate with the TestDriver API.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
Connection options
Promise<Object> - Sandbox instance details including instanceId, ip, vncPort, etc.
Examples
Basic connection:disconnect()
Disconnect from the sandbox and clean up resources.Promise<void>
Example:
Instance Information
getInstance()
Get the current sandbox instance details.Object | null - Sandbox instance information
Example:
getSessionId()
Get the current session ID for tracking and debugging.string | null - Session ID
Example:
Logging & Events
setLogging()
Enable or disable console logging at runtime.enabled(boolean) - Whether to enable logging
getEmitter()
Get the event emitter for custom event handling.EventEmitter2 - Event emitter instance
Example:
Complete Example
Best Practices
Reuse sandboxes across tests
Reuse sandboxes across tests
Use
beforeAll/afterAll to create one sandbox per test suite rather than per test. This significantly reduces execution time.Handle connection errors gracefully
Handle connection errors gracefully
Wrap
connect() in a try-catch block to handle network issues or quota limits:Always disconnect
Always disconnect
Use
afterAll or try-finally blocks to ensure disconnect() is called even if tests fail. This prevents orphaned sandboxes.Use environment variables for API keys
Use environment variables for API keys
Never hardcode API keys. The SDK automatically loads
TD_API_KEY from your .env file:.env

