Protect sensitive information such as passwords, API keys, and tokens in your TestDriver tests.
Typing Secrets Securely
When you type sensitive information such as passwords, use the secret: true option. This stops TestDriver from a log or a store of the value:
javascriptimport { test } from 'vitest'; import { chrome } from 'testdriverai/presets'; test('login with secure password', async (context) => { const { testdriver } = await chrome(context, { url: 'https://myapp.com/login' }); await testdriver.find('email input').click(); await testdriver.type(process.env.TD_USERNAME); await testdriver.find('password input').click(); // Password is masked in logs and recordings await testdriver.type(process.env.TD_PASSWORD, { secret: true }); await testdriver.find('login button').click(); await testdriver.assert('dashboard is visible'); });
Storing Secrets in GitHub
Store sensitive credentials as GitHub repository secrets. Then they are never in your code:
Local Development
For local development, store secrets in a .env file:
bashTD_API_KEY=your_api_key_here TD_USERNAME=testuser@example.com TD_PASSWORD=your_secure_password
Complete Example
Here's a full login test with proper secrets handling:
javascriptimport { test, expect } from 'vitest'; import { chrome } from 'testdriverai/presets'; test('secure login flow', async (context) => { const { testdriver } = await chrome(context, { url: process.env.TD_WEBSITE || 'https://staging.myapp.com' }); // Enter username (not sensitive) await testdriver.find('email input').click(); await testdriver.type(process.env.TD_USERNAME); // Enter password securely await testdriver.find('password input').click(); await testdriver.type(process.env.TD_PASSWORD, { secret: true }); // Submit login await testdriver.find('login button').click(); // Verify successful login const loggedIn = await testdriver.assert('user is logged in'); expect(loggedIn).toBeTruthy(); });


