@testdriver.ai/playwright
is a backwards-compatible wrapper around @playwright/test
that uses TestDriver’s Vision AI to:
- Make natural language assertions
- Replace brittle selectors with natural language
- Perform actions with a prompt
- Test with an automated agent
Prerequisites
1
Create a TestDriver Account
You will need a TestDriver Pro account ($20/month) to get an API key.
Sign Up for TestDriver
2
Set up your environment
Copy your API key from the TestDriver dashboard, and set it as an environment variable.
Export an environment variable on macOS or Linux systems
Setup Playwright
1
Initialize Playwright
This is a condensed version of Playwright’s Installation Instructions.If you’re new to Playwright, you should follow their guide first.
Setup @testdriver.ai/playwright
1
Install TestDriver
@testdriver.ai/playwright
as a backwards-compatible wrapper around @playwright/test
:2
Run Playwright
Before we start using TestDriver in our tests, run Playwright in UI Mode:
Clicking the ▶️ button should successfully run the tests in the UI,
just as they did before with

playwright test
in the CLI.3
Import TestDriver
For the sake of simplicity, we’ll be working with one test file for now.Open Click the button to run the test and verify everything still works.
tests/example.spec.ts
in your editor & rename the @playwright/test
import to @testdriver.ai/playwright
:tests/example.spec.ts
Click the button to automatically re-run tests on save.
Usage
Because TestDriver uses AI vision instead of selectors, we can use natural language for assertions, locating, performing actions, or even having an agent test for you!Assertions with expect.toMatchPrompt
Replace toBeVisible
with toMatchPrompt
to assert that the element is visible on the screen:
tests/example.spec.ts
toMatchPrompt
, natural language acts as a description, selector, and assertion in one
TestDriver can reduce the amount of complexity in your tests, but you can
still “opt-in” to Playwright assertions and selectors if you need to (e.g.
validating accessibility with
page.getByRole
).Locating elements with testdriver.locate
TestDriver can replace data-testid
s, getByRole
, and CSS selectors with natural language.
First, update your test to get access to the testdriver
fixture:
tests/example.spec.ts
getByRole
with testdriver.locate
:
tests/example.spec.ts
In the example above, you can still use Playwright to assert that the element is indeed a link for accessibility:This way you can write user-centric tests and validate the implementation.
tests/example.spec.ts
Performing actions with testdriver.act
We can combine locate
and click
from the previous example into one line with testdriver.act
:
tests/example.spec.ts
Agentic tests with test.agent
TestDriver can automatically perform the entire test for you with an AI agent:
tests/example.spec.ts
test.describe
to describe the test still,
but replaced the test
itself with test.agent
.
Use
test.beforEach
to prepare the page for the agent (e.g.
page.goto
, calling
an API to create a user). Use
test.afterEach
to clean up after the agent (e.g. page.close
) or perform additional logic
(e.g. clearing the session).Conclusion
With@testdriver.ai/playwright
, you can use as much or as little of Playwright’s or TestDriver’s API as you need to validate correctness. It’s up to you!