Use this file to discover all available pages before exploring further.
TestDriver provisions a fresh cloud VM for every test by default. This guide covers how to configure Linux and Windows machines, reduce startup time by keeping machines alive between runs, use provision scripts for repeatable setup, and install custom software on the fly.
Windows sandboxes use EC2 instances and take longer to boot than Linux (E2B) sandboxes — typically 1–3 minutes for a cold start. See Keeping Machines Alive below to avoid this cost on repeated runs.
Windows (and Linux) cold starts can be expensive if you’re iterating quickly. Use keepAlive + reconnect to reuse the same VM across multiple test runs.
Every time the SDK successfully connects to a sandbox, it records the sandbox id in .testdriver/last-sandbox inside your project directory. The next test that opts in with reconnect: true reads that file and reattaches automatically — no manual id tracking required.Provision calls (testdriver.provision.chrome(...), vscode(...), etc.) are skipped when reconnecting, because the application is already running inside the sandbox from the previous run.
.testdriver/last-sandbox is already covered by the default TestDriver .gitignore. Don’t commit it.
A common pattern is to break a long flow into focused describe blocks that share one sandbox — the first block provisions and signs in, later blocks reconnect and continue:
import { describe, expect, it } from "vitest";import { TestDriver } from "testdriverai/vitest/hooks";const KEEP_ALIVE_MS = 5 * 60 * 1000;describe("step 1 — log in", () => { it("signs in and lands on the dashboard", async (context) => { const testdriver = TestDriver(context, { keepAlive: KEEP_ALIVE_MS }); await testdriver.provision.chrome({ url: "https://example.com/login" }); await testdriver.find("username input").click(); await testdriver.type("standard_user"); await testdriver.pressKeys(["tab"]); await testdriver.type("secret_sauce", { secret: true }); await testdriver.pressKeys(["enter"]); expect(await testdriver.assert("the dashboard is visible")).toBeTruthy(); });});describe("step 2 — add to cart", () => { it("reuses the logged-in sandbox", async (context) => { const testdriver = TestDriver(context, { reconnect: true, // ← skip provisioning, reattach keepAlive: KEEP_ALIVE_MS, }); await testdriver.find("Add to cart").click(); await testdriver.find("cart icon").click(); expect(await testdriver.assert("the cart has an item")).toBeTruthy(); });});describe("step 3 — check out", () => { it("continues from the cart state", async (context) => { const testdriver = TestDriver(context, { reconnect: true, keepAlive: 30_000 }); await testdriver.find("Checkout").click(); expect(await testdriver.assert("the checkout form is visible")).toBeTruthy(); });});
Vitest runs test files in parallel by default. Within a single file, describe/it blocks run in source order, so reconnect chaining works as written. To chain across multiple files, run them sequentially (e.g. vitest run --sequence.concurrent=false or place them in a single project pool with workers set to 1).
keepAlive is a duration in milliseconds. After the SDK disconnects, the server keeps the VM running for that long before terminating it. The default is 60000 (1 minute). Note: keepAlive: 0 currently falls back to the default disconnect grace period rather than terminating immediately, so use a positive duration when you want to control the grace window explicitly.
Provision scripts let you run arbitrary setup steps before your test starts — downloading fixtures, seeding a database, configuring environment variables, and more. Use testdriver.exec() to run shell or PowerShell commands directly in the sandbox.
exec() Reference
Full reference for running shell and PowerShell commands in the sandbox.
await testdriver.provision.chrome({ url: "https://myapp.com" });// Run a setup script from your repoawait testdriver.exec("sh", ` curl -s https://myapp.com/api/reset-test-db -X POST echo "Test DB reset"`, 30000);
You can install software at the start of a test using exec(). This works for any package available via apt, brew, choco, winget, npm, pip, or direct download.
Installing software at test start adds to your test duration. For software you use in every test, consider preloading it into a custom VM image via the Enterprise self-hosted plan.
Installing packages at runtime works well for occasional or lightweight dependencies. But if you’re installing the same 5-minute setup on every test run, you’re wasting time and credits.With the Self-Hosted Enterprise plan you get access to our golden VM base image and Packer scripts, so you can bake your applications, dependencies, and configuration directly into a custom AMI. Tests spin up with everything already installed — zero setup time.
Self-Hosted Enterprise
Preload software, configure custom hardware, and run unlimited tests with a flat license fee. Our team assists with deployment and setup.