Quickstart
Get up and running with annotation-driven testing in 5 minutes.
Install packages
npm
npm install @lytics/playwright-annotations @lytics/playwright-reporter @lytics/playwright-adaptersCreate a reporter file
Playwright reporters must be specified as file paths. Create a reporter file that extends CoreReporter:
// reporter.ts
import { CoreReporter } from '@lytics/playwright-reporter';
import { FilesystemAdapter } from '@lytics/playwright-adapters/filesystem';
class CustomReporter extends CoreReporter {
constructor() {
super({
adapters: [
new FilesystemAdapter({ outputDir: './test-results' })
]
});
}
}
export default CustomReporter;Configure Playwright
Reference the reporter file in your config:
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
reporter: [
['list'], // Keep the built-in list reporter for console output
['./reporter.ts'],
],
// ... rest of your config
});Add annotations to your tests
// tests/account-security.spec.ts
import { test, expect } from '@playwright/test';
import { pushSuiteAnnotation, pushTestAnnotations } from '@lytics/playwright-annotations';
test.describe('Account Security @smoke', () => {
// Set the suite annotation in beforeEach
test.beforeEach(async ({}, testInfo) => {
pushSuiteAnnotation(testInfo, 'ACCOUNT_SECURITY');
});
test('user can view access tokens', async ({ page }, testInfo) => {
// Set test-specific annotations
pushTestAnnotations(testInfo, {
journeyId: 'ACCOUNT_SECURITY_VIEW-TOKENS',
testCaseId: 'ACCOUNT_SECURITY_VIEW-TOKENS_VALID',
});
// Your test implementation
await page.goto('/settings/tokens');
await expect(page.getByRole('heading', { name: 'Access Tokens' })).toBeVisible();
});
test('shows empty state when no tokens exist', async ({ page }, testInfo) => {
pushTestAnnotations(testInfo, {
journeyId: 'ACCOUNT_SECURITY_VIEW-TOKENS',
testCaseId: 'ACCOUNT_SECURITY_VIEW-TOKENS_EMPTY',
});
await page.goto('/settings/tokens');
await expect(page.getByText('No tokens found')).toBeVisible();
});
});Run your tests
npx playwright testCheck the results
After running tests, youβll find JSON files in ./test-results/:
test-results/
βββ test-results/
β βββ ACCOUNT_SECURITY_VIEW-TOKENS_VALID-2024-01-01T00-00-00.000Z.json
β βββ ACCOUNT_SECURITY_VIEW-TOKENS_EMPTY-2024-01-01T00-00-01.000Z.json
βββ test-runs/
βββ test-run-local-2024-01-01T00-00-00.000Z.json
βββ latest.jsonWhatβs Next?
Tests without annotations will be skipped with a warning. Make sure all tests have journeyId and testCaseId annotations.
Add more adapters
Send results to multiple destinations by updating your reporter file:
// reporter.ts
import { CoreReporter } from '@lytics/playwright-reporter';
import { FilesystemAdapter } from '@lytics/playwright-adapters/filesystem';
import { SlackAdapter } from '@lytics/playwright-adapters/slack';
class CustomReporter extends CoreReporter {
constructor() {
super({
adapters: [
new FilesystemAdapter({ outputDir: './test-results' }),
new SlackAdapter({
webhookUrl: process.env.SLACK_WEBHOOK_URL!,
environment: 'Production',
})
]
});
}
}
export default CustomReporter;Add environment metadata
Enrich test runs with CI/CD information:
// reporter.ts
class CustomReporter extends CoreReporter {
constructor() {
super({
adapters: [/* ... */],
environmentEnricher: () => ({
branch: process.env.GITHUB_REF,
commit: process.env.GITHUB_SHA,
author: process.env.GITHUB_ACTOR,
buildNumber: process.env.GITHUB_RUN_NUMBER,
})
});
}
}Learn More
- Core Concepts β Understand the annotation hierarchy
- Annotations β Full annotation API reference
- Reporter β Reporter configuration and types
- Adapters β Available storage adapters
Last updated on