Test IT Playwright Adapter
raw JSON →The `testit-adapter-playwright` package provides a robust integration layer between the Playwright test automation framework and the Test IT Test Management System (TMS). It automates the process of publishing test results, logs, and attachments from Playwright test runs directly into a Test IT instance. The current stable version is `4.0.2-TMS-5.7`, with parallel releases like `4.0.2` for different TMS versions, indicating an active development and maintenance cadence. Key differentiators include seamless mapping of Playwright tests to TMS work items using decorators like `externalId`, automatic reporting of test statuses (passed, failed, skipped), and the ability to attach rich media (screenshots, videos, logs) directly from Playwright's capabilities. It allows for flexible configuration via environment variables or a Playwright configuration file, supporting various adapter modes for managing test runs within TMS.
Common errors
error Error: Missing required configuration: TMS_URL. Please provide it via config file or environment variable TMS_URL. ↓
TMS_URL environment variable or provide url in the TestITReporter options in playwright.config.ts. error TypeError: TestITReporter is not a constructor ↓
import { TestITReporter } from 'testit-adapter-playwright/reporter'; in a TypeScript or ESM file (e.g., playwright.config.ts), and that your project is configured for ESM. error Error: Test run with ID '...' not found in Test IT. ↓
TMS_TEST_RUN_ID environment variable or the testRunId option in TestITReporter is correct and corresponds to an active test run in your Test IT instance. Alternatively, omit testRunId to allow the adapter to create a new one (if adapterMode 1 is configured to do so). error Error: Failed to upload attachment '...' - [Network Error / API Error] ↓
TMS_PRIVATE_TOKEN is correct and has necessary permissions. Ensure the file path provided to attachment decorator/function is valid and accessible by the test runner process. Warnings
breaking Version 4.0.0 introduced significant changes, including 'sync-storage' and adapter hardening features. While no explicit breaking API changes were detailed, it may alter behavior related to how test run data is synchronized and managed, potentially requiring updates to existing automation setups. ↓
gotcha Sensitive configuration values like `privateToken` should always be handled securely, preferably via environment variables (`TMS_PRIVATE_TOKEN`) rather than hardcoding them directly in `playwright.config.ts`. Exposing these in source control can lead to security vulnerabilities. ↓
gotcha The package versioning often includes a `-TMS-X.Y` suffix (e.g., `4.0.2-TMS-5.7`), indicating compatibility with a specific Test IT TMS version. Using an adapter version incompatible with your TMS instance can lead to reporting errors or unexpected behavior. ↓
gotcha Incorrect or missing Playwright configuration for the reporter, especially the `reporter` array format, can lead to the adapter not being initialized or reporting failures. Ensure `TestITReporter` is correctly passed with its options. ↓
Install
npm install testit-adapter-playwright yarn add testit-adapter-playwright pnpm add testit-adapter-playwright Imports
- TestITReporter wrong
const { TestITReporter } = require('testit-adapter-playwright/reporter');correctimport { TestITReporter } from 'testit-adapter-playwright/reporter'; - externalId wrong
import { externalId } from '@testit/decorators';correctimport { test, externalId } from 'testit-adapter-playwright'; - attachment wrong
import { addAttachments } from 'testit-adapter-playwright';correctimport { test, attachment } from 'testit-adapter-playwright'; - LinkType
import { LinkType } from 'testit-adapter-playwright';
Quickstart
import { defineConfig, devices } from '@playwright/test';
import { TestITReporter } from 'testit-adapter-playwright/reporter';
export default defineConfig({
testDir: './tests',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: [[TestITReporter, {
url: process.env.TMS_URL ?? '',
privateToken: process.env.TMS_PRIVATE_TOKEN ?? '',
projectId: process.env.TMS_PROJECT_ID ?? '',
configurationId: process.env.TMS_CONFIGURATION_ID ?? '',
testRunName: process.env.TMS_TEST_RUN_NAME ?? 'Playwright Test Run ' + new Date().toISOString(),
adapterMode: 1 // 1: Use existing test run ID, create if not provided; 2: Create new test run
}], 'html'],
use: {
trace: 'on-first-retry',
},
projects: [
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
],
});
// tests/example.spec.ts
import { test, expect, externalId, attachment } from 'testit-adapter-playwright';
import path from 'path';
import fs from 'fs';
test.describe('Example Test IT Integration', () => {
externalId('TMS-1234', 'Verify basic page load');
test('should navigate to example.com and take a screenshot', async ({ page }) => {
await page.goto('https://www.example.com');
await expect(page).toHaveTitle(/Example Domain/);
const screenshotPath = path.join(__dirname, 'screenshot.png');
await page.screenshot({ path: screenshotPath });
attachment('Page Load Screenshot', screenshotPath);
// Clean up created file
fs.unlinkSync(screenshotPath);
});
externalId('TMS-5678', 'Check heading text');
test('should verify heading text', async ({ page }) => {
await page.goto('https://www.example.com');
await expect(page.locator('h1')).toHaveText('Example Domain');
});
});