Skip to main content
Scale your test suite with reusable code patterns and dynamic data to reduce duplication and maintain consistency across thousands of tests.

Code Snippets for Reusability

Scale your test suite with reusable code snippets to reduce duplication and maintain consistency:
test/helpers/auth.js
// Reusable authentication helpers
export async function login(testdriver, { email, password }) {
  await testdriver.find('email input').type(email);
  await testdriver.find('password input').type(password);
  await testdriver.find('login button').click();
  await testdriver.assert('logged in successfully');
}

export async function logout(testdriver) {
  await testdriver.find('user menu').click();
  await testdriver.find('logout button').click();
}
test/checkout.test.js
import { login } from './helpers/auth.js';

test('checkout flow', async (context) => {
  const { testdriver } = await chrome(context, { url });
  await login(testdriver, { 
    email: '[email protected]',
    password: 'password123' 
  });
  // Continue with checkout test
});
Reusable snippets reduce test maintenance time by up to 70% in large test suites.

Dynamic Variables for Data-Driven Tests

Scale your testing with dynamic data to cover more scenarios:
import { test } from 'vitest';
import { chrome } from 'testdriverai/presets';

test('multi-environment testing', async (context) => {
  const env = process.env.TEST_ENV || 'staging';
  const urls = {
    dev: 'https://dev.myapp.com',
    staging: 'https://staging.myapp.com',
    production: 'https://myapp.com'
  };

  const { testdriver } = await chrome(context, { 
    url: urls[env] 
  });

  await testdriver.assert('app is running');
});
# Run against different environments
TEST_ENV=dev npx vitest run
TEST_ENV=staging npx vitest run
TEST_ENV=production npx vitest run

Dynamic Variables Best Practices

  • Environment configs: Store URLs, credentials, and settings in env vars
  • Test fixtures: Maintain reusable test data in separate files
  • Data generators: Use libraries like Faker for unique test data
  • Parameterization: Test multiple scenarios with test.each()
  • CI/CD integration: Pass dynamic values via environment variables

Secure Secrets Management

Protect sensitive data in your tests with built-in secrets handling:
import { test } from 'vitest';
import { chrome } from 'testdriverai/presets';

test('login with secret password', async (context) => {
  const { testdriver } = await chrome(context, { url });

  await testdriver.find('email input').type('[email protected]');
  
  // Password is never logged or cached
  await testdriver.find('password input').type(process.env.TEST_PASSWORD, { 
    secret: true 
  });
  
  await testdriver.find('login button').click();
  await testdriver.assert('logged in successfully');
});
The secret: true option prevents sensitive data from appearing in logs, dashcam replays, or cache entries.
Never hardcode secrets in test files or commit them to version control. Always use environment variables or secure secret management systems.

Familiar Test Syntax

TestDriver works with the test frameworks you already know:
import { test, describe, beforeAll, afterAll } from 'vitest';
import { chrome } from 'testdriverai/presets';

describe('My Feature', () => {
  test('should work', async (context) => {
    const { testdriver } = await chrome(context, { url });
    await testdriver.find('button').click();
  });
});

Existing Systems Integration

Drop TestDriver into your current workflow without disruption:
import { test, expect } from 'vitest';
import { chrome } from 'testdriverai/presets';

test('integrates with existing assertions', async (context) => {
  const { testdriver } = await chrome(context, { url });

  // Use TestDriver's AI assertions
  await testdriver.assert('welcome message is visible');

  // Or use traditional assertions
  const button = await testdriver.find('submit button');
  expect(button.coordinates).toBeDefined();
  expect(button.text).toContain('Submit');

  // Mix and match as needed
  const element = await testdriver.exec('js', 'document.title');
  expect(element).toBe('My App');
});

Learn More