Allure Report Integration with Playwright
Allure Report Integration with Playwright
Integrating Allure Reports with Playwright provides detailed, interactive test reports that help visualize test results with rich information like steps, attachments, and screenshots.
Here’s a complete guide to integrate Allure Reports with Playwright using JavaScript/TypeScript.
✅ Prerequisites
Node.js installed
Playwright project set up
npm or yarn as package manager
π¦ Step 1: Install Dependencies
Install Allure commandline and Playwright Allure reporter:
bash
Copy
Edit
npm install --save-dev allure-playwright allure-commandline
Optionally, install Allure globally:
bash
Copy
Edit
npm install -g allure-commandline
π ️ Step 2: Configure Playwright to Use Allure Reporter
Edit your playwright.config.ts or playwright.config.js:
ts
Copy
Edit
import { defineConfig } from '@playwright/test';
export default defineConfig({
reporter: [
['list'],
['allure-playwright'],
],
use: {
screenshot: 'only-on-failure', // optional but useful
video: 'retain-on-failure', // optional
},
});
π§ͺ Step 3: Write Tests with Allure Metadata (Optional)
You can add metadata using test.info().annotations or allure API:
ts
Copy
Edit
import { test, expect } from '@playwright/test';
import { allure } from 'allure-playwright';
test('My test with Allure metadata', async ({ page }) => {
allure.label('owner', 'QA Team');
allure.severity('critical');
await page.goto('https://example.com');
await expect(page).toHaveTitle(/Example/);
});
π Step 4: Run Tests and Generate Report
Run tests:
bash
Copy
Edit
npx playwright test
Generate the Allure report:
bash
Copy
Edit
npx allure generate ./allure-results --clean -o ./allure-report
Open the report:
bash
Copy
Edit
npx allure open ./allure-report
π Folder Structure
After running tests:
allure-results/: Raw result files
allure-report/: Generated report (after running allure generate)
π§Ό Optional: Add Scripts to package.json
json
Copy
Edit
"scripts": {
"test": "playwright test",
"allure:generate": "allure generate allure-results --clean -o allure-report",
"allure:open": "allure open allure-report"
}
Now you can run:
bash
Copy
Edit
npm run test
npm run allure:generate
npm run allure:open
π§© Tips
You can attach screenshots, logs, and videos to Allure using Playwright hooks.
Use test.step() to break down complex steps — Allure will show them clearly.
CI/CD integration is supported (e.g., GitHub Actions, Jenkins).
Let me know if you'd like a working project example or help with setting it up in a CI pipeline!
Learn Playwright Training Course in Hyderabad
Read More
CI/CD Pipeline Setup with GitHub Actions and Playwright
Integrating Playwright with Jenkins
Visit Our IHUB Talent Training Institute in Hyderabad
Comments
Post a Comment