Writing Effective AI Tests with TestDriver
Best practices for writing reliable, maintainable end-to-end tests using TestDriver's AI engine. Learn how to structure prompts, handle dynamic content, and debug failures.
Automate and scale manual testing with AI ->
Writing Effective AI Tests with TestDriver
Writing tests with TestDriver’s AI engine is different from traditional selector-based testing. Instead of writing code that clicks specific CSS selectors, you describe what you want to accomplish in natural language.
The Golden Rule: Describe Intent, Not Implementation
❌ Avoid describing implementation details:
- prompt: Click the button with class "btn-primary" in the nav
✅ Describe user intent instead:
- prompt: Click the "Sign Up" button in the navigation
The second approach is resilient to UI changes — even if the button’s CSS class or position changes, TestDriver understands what you mean.
Structuring Your Prompts
Be Specific About UI Elements
When referring to UI elements, use the visible label or text:
steps:
- prompt: Open the user settings menu in the top right
- prompt: Select "Account Preferences" from the dropdown
- prompt: Change the notification frequency to "Weekly"
- prompt: Click "Save Changes"
- prompt: Confirm that a success message appears
Use Assertions Liberally
TestDriver can verify the state of your application:
- prompt: Assert that the user's name "Jane Doe" appears in the header
- prompt: Verify that there are exactly 3 items in the shopping cart
- prompt: Confirm that the error message is not visible
Chain Related Actions
Group related actions into logical sequences:
version: 4
steps:
# Setup: log in first
- prompt: Navigate to https://app.example.com and log in with test@example.com / password123
# Core test: create a new project
- prompt: Click "New Project" in the sidebar
- prompt: Enter "My Test Project" as the project name
- prompt: Select "Web Application" as the project type
- prompt: Click "Create Project"
- prompt: Assert that we're now on the project dashboard with the name "My Test Project"
Handling Dynamic Content
Waiting for Content to Load
TestDriver automatically handles most loading states, but for long operations you can be explicit:
- prompt: Click "Generate Report" and wait for the report to finish generating
- prompt: Assert that the report PDF download link is available
Testing with Data
For tests that need specific data, use your test environment’s setup:
- prompt: Navigate to /admin/users and find the user "testuser@example.com"
- prompt: Click "Edit" next to that user
- prompt: Change their role to "Administrator"
- prompt: Save the changes and confirm the role updated successfully
Debugging Test Failures
When a test fails, TestDriver provides:
- Screenshot of the exact moment of failure
- AI explanation of what went wrong
- Suggested fixes for your prompt
Common Failure Patterns
“Element not found” — The AI couldn’t locate the described element:
- Make the description more specific
- Check that the element is actually visible in the viewport
- Verify the page has fully loaded
“Assertion failed” — The expected state wasn’t met:
- Check your timing (add “wait for” if needed)
- Verify your test data is in the expected state
- Review the screenshot for clues
Performance Testing
Include performance assertions in your tests:
- prompt: Navigate to the homepage and assert it loads within 3 seconds
- prompt: Open the product catalog and verify the page responds quickly without visible lag
Reusable Test Fragments
Break complex flows into smaller, reusable test files:
# auth.yml - reusable login flow
version: 4
steps:
- prompt: Navigate to https://app.example.com/login
- prompt: Enter credentials email@test.com / password and click Sign In
- prompt: Assert the dashboard is visible
Then reference it in other tests using your CI configuration to run multiple test files in sequence.
Next Steps
- Explore the TestDriver documentation for advanced configuration
- Check the changelog for the latest features
Automate and scale manual testing with AI
TestDriver uses computer-use AI to test any app - write tests in plain English and run them anywhere.