testdriverai init installs three things so you can write, run, and debug real end-to-end tests from chat:
- The agent: an expert test-writer. It controls a live sandbox, writes code after each step, and re-runs the test until it passes.
- Skills: small instruction files that teach the agent the correct syntax for each TestDriver capability (
find,click,type,assert, and more). - The MCP server: exposes TestDriver’s computer-use tools through the Model Context Protocol so any MCP client can call them.
Prerequisites
- Node.js 20.19 or later
- A TestDriver account. Create one for free. You get 60 device minutes, no credit card required.
1
Scaffold a project
Make a new folder (or open an existing project) and run
init:init asks two questions:- How to authenticate. Choose Login with browser to sign in and save your key automatically, or paste an API key from console.testdriver.ai/settings. Either way, it is saved to
.envasTD_API_KEY. - Which AI clients to set up. Pick VS Code, Cursor, Claude Code, and others, or press Enter to skip.
initdetects the clients already present in your project and pre-selects them. You can runinitagain later to add more; it merges the TestDriver entry into your existing config and does not overwrite your other servers.
vitest and testdriverai and creates these files:2
Connect your AI client
init writes the agent, skills, and MCP server config in the format and location each client expects. Here is what it installs and where.The agent
The TestDriver agent runs inside your AI client (Claude Code, Cursor, VS Code, and others). Unlike a chat assistant that only suggests code, it works iteratively on a live sandbox: it starts a session, performs each action, writes the code to your test file, confirms the result with a screenshot, and re-runs the test until it passes.Skills
Skills are small instruction files, one per TestDriver capability, in the AnthropicSKILL.md format. There are over 100, generated from this documentation, covering every action and concept: find, click, type, assert, check, scroll, press-keys, provision, caching, secrets, CI/CD, and more.MCP server
The TestDriver MCP server exposes the computer-use tools (session_start, find, click, type, assert, check, screenshot, and more). It runs as a local stdio process and authenticates with your TD_API_KEY:Configure the MCP server by hand
Configure the MCP server by hand
Each client uses a different top-level key for MCP servers. The most common manual-config mistake is using
mcpServers for VS Code (which needs servers), Codex (TOML [mcp_servers]), or Zed (context_servers).- Claude Code
- Claude Desktop
- Cursor
- VS Code
- Windsurf
- Codex
- Zed
Add this to
.mcp.json at your project root (or ~/.claude.json for all projects):Web-based clients (Lovable, Replit, v0)
Web-based clients (Lovable, Replit, v0)
These run in the browser, so they cannot start the MCP server as a local process. Configure them through each product’s UI.Lovable
- Connect your GitHub repo, then run
npx testdriverai init --client lovable. This writesAGENTS.mdand the skills into the repo so the Lovable agent can use them. - In Lovable, open Settings → MCP and add the TestDriver server.
- Run
npx testdriverai init --client replitto writereplit.mdwith the TestDriver agent guidance. - In Replit, open Tools → Integrations → MCP and add a custom MCP server.
- Open v0.app/chat/settings/mcp-connections and add the TestDriver MCP connection.
- Paste the agent guidance into Instructions (the + in the prompt bar).
Verify the install
Open your client’s chat and ask the agent to write a test:tests/ and runs it for you. If the tools do not appear, confirm that TD_API_KEY is set and restart the client.3
Run the example test
TestDriver tests are plain Vitest tests. Run them with:Here is what happens:Open it to see the video recording, screenshots, and logs for each step.
- A cloud sandbox starts and opens Chrome at the demo app.
- A live preview of the sandbox opens in your browser so you can watch.
- The test finds the login form, types credentials, adds an item to the cart, and asserts the cart has an item.
- The sandbox is torn down and results are uploaded.
The first run takes a minute or two while the sandbox boots. Later runs are faster because element locations are cached.
4
Read the example test
Open The pieces you will use most:
tests/example.test.js. Every TestDriver test follows the same shape: create an instance, provision an app, then find, act, and assert in natural language.tests/example.test.js
provision.chrome()starts a browser (or a desktop app) in the sandboxfind()locates an element by description; then call.click(),.hover(), and so ontype()andpressKeys()send keyboard inputassert()asks a yes/no question about the screen
5
Write your own test
The fastest way is to ask the agent:Or write it by hand. Create Run just that file:
tests/search.test.js and point it at a site you want to test:tests/search.test.js
6
Run in CI
init already created .github/workflows/testdriver.yml. Push your project to GitHub, then add TD_API_KEY as a repository secret (Settings → Secrets and variables → Actions). Your tests now run on every pull request.See CI/CD for other providers and for keyless auth with the TestDriver GitHub App.Troubleshooting
TD_API_KEY is not configured
TD_API_KEY is not configured
The SDK reads You can also export it in your shell:
TD_API_KEY from .env in the folder where you run vitest. Make sure the file exists and has this line:.env
export TD_API_KEY=your_api_key.The agent or MCP tools do not appear in my client
The agent or MCP tools do not appear in my client
Confirm
TD_API_KEY is set, check that the MCP config uses the correct top-level key for your client (see the table above), and restart the client. Running npx testdriverai init --client <name> again rewrites the config in the correct format.No test files found
No test files found
Vitest only picks up files that match
*.test.js, *.test.mjs, or *.spec.*. Check the file name and that the file is inside your project folder.Test times out
Test times out
Sandbox provisioning and teardown take time.
init sets testTimeout and hookTimeout to 5 minutes in vitest.config.js. If you wrote the config by hand, add both values.Next steps
Generating tests
Prompting patterns that get the best tests out of the agent.
Walkthrough
Provision apps, locate elements, perform actions, and make assertions.
Reusable code
Share login flows and other steps across tests.
Secrets
Keep passwords and tokens out of logs and recordings.

