Playwright
npm install @tracera/playwright
Node.js ≥ 22.19 चाहिए (देखें ऑटोटेस्ट एडेप्टर)। @tracera/playwright npm पर.
playwright.config.ts में:
import '@tracera/playwright/register';
import { defineConfig } from '@playwright/test';
export default defineConfig({
reporter: [['@tracera/playwright/reporter']],
use: {
screenshot: 'only-on-failure',
video: 'retain-on-failure',
trace: 'retain-on-failure', // or "on-first-retry"
},
});
import "@tracera/playwright/register" हर worker में test.step / hooks पैच करता है ताकि tracera.comment / tracera.error मौजूदा स्टेप पर जाएँ।
कॉन्फ़िग में एक बार screenshot / video / trace चालू करें — Playwright आर्टिफ़ैक्ट अपने आप Tracera रिजल्ट में फॉरवर्ड हो जाते हैं (परिणाम पर अधिकतम 10 अटैचमेंट और हर चरण पर 10)। रीट्राई चालू हो तो केवल अंतिम प्रयास रिपोर्ट होता है। अगर वह रीट्राई है (retry > 0), परिणाम Env टैब में PLAYWRIGHT_RETRY आता है — Playwright का testInfo.retry (1 दूसरा रन है)।
एनवायरनमेंट वेरिएबल और रन मोड: ऑटोटेस्ट एडेप्टर।
testCaseId और autotestName बाँधना
test / expect @playwright/test से इम्पोर्ट करें, tracera / annotations @tracera/playwright से।
अगर autotestName न दें, तो एडेप्टर Playwright टेस्ट का नाम लेता है।
घोषणा पर (पसंदीदा):
import { test, expect } from '@playwright/test';
import { annotations } from '@tracera/playwright';
test('login', { annotation: annotations(42, 'e2e/login') }, async ({ page }) => {
await page.goto('/login');
await expect(page.getByRole('button', { name: 'Sign in' })).toBeVisible();
});
टेस्ट के अंदर (अगर annotations पहले से केस बाँध चुके हों तो वैकल्पिक):
import { test, expect } from '@playwright/test';
import { tracera } from '@tracera/playwright';
test('login', async ({ page }) => {
tracera.testCase(42, 'e2e/login');
await page.goto('/login');
await expect(page.getByRole('button', { name: 'Sign in' })).toBeVisible();
});
स्टेप्स
Playwright का test.step इस्तेमाल करें — यह टेस्ट में रिकॉर्ड होता है। अगर अन्य रनर्स जैसा साझा API चाहिए तो tracera.step भी वही रिपोर्टिंग है। test.beforeEach के अंदर स्टेप्स सेटअप में जाते हैं; test.afterEach के अंदर स्टेप्स टीयरडाउन में।
import { test } from '@playwright/test';
import { annotations } from '@tracera/playwright';
test.beforeEach(async ({ page }) => {
await test.step('open shop', async () => {
await page.goto('/shop');
});
});
test('checkout', { annotation: annotations(10, 'e2e/checkout') }, async ({ page }) => {
await test.step('add to cart', async () => {
await page.getByRole('button', { name: 'Add' }).click();
});
});
test.afterEach(async ({ page }) => {
await test.step('cleanup', async () => {
await page.goto('/cart/clear');
});
});
टिप्पणियाँ, त्रुटियाँ और अटैचमेंट
स्टेप के अंदर उस स्टेप के फ़ील्ड। स्टेप के बाहर रिजल्ट के फ़ील्ड।
import { test } from '@playwright/test';
import { tracera, annotations } from '@tracera/playwright';
test('login', { annotation: annotations(42, 'e2e/login') }, async ({ page }, testInfo) => {
tracera.comment('result-level note');
tracera.error('result-level error text');
await test.step('open login', async () => {
await page.goto('/login');
tracera.comment('landed on login');
});
await testInfo.attach('suite-log.txt', {
body: 'finished login flow',
contentType: 'text/plain',
});
});
कस्टम फ़ाइलों के लिए testInfo.attach इस्तेमाल करें। Playwright स्क्रीनशॉट, ब्राउज़र रिकॉर्डिंग और trace खुद अटैच करता है — Tracera में इमेज लाइटबॉक्स में खुलती हैं, रिकॉर्डिंग इनलाइन चलती है, और traces Trace Viewer में खुलते हैं।
पैरामीटराइज़्ड टेस्ट
import { test, expect } from '@playwright/test';
import { annotations } from '@tracera/playwright';
const rows = [
{ id: 42, name: 'e2e/login-ok', path: '/login' },
{ id: 43, name: 'e2e/login-sso', path: '/login/sso' },
];
for (const row of rows) {
test(row.name, { annotation: annotations(row.id, row.name) }, async ({ page }) => {
await test.step('open', async () => {
await page.goto(row.path);
});
await expect(page.getByRole('button', { name: 'Sign in' })).toBeVisible();
});
}
या बॉडी में annotations की जगह tracera.testCase(row.id, row.name) कॉल करें।
कस्टम fixtures
स्टॉक Playwright test को हमेशा की तरह extend करें:
import { test as base, expect } from '@playwright/test';
import { tracera } from '@tracera/playwright';
export const test = base.extend<{ asUser: void }>({
asUser: [
async ({ page }, use) => {
await page.goto('/login');
await page.getByLabel('Email').fill('user@example.com');
await page.getByRole('button', { name: 'Sign in' }).click();
await use();
},
{ auto: true },
],
});
test('dashboard', async ({ page }) => {
tracera.testCase(99, 'e2e/dashboard');
await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
});