Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
allure-playwright
Advanced tools
The allure-playwright package integrates Allure reporting capabilities with Playwright, a popular end-to-end testing framework. It allows you to generate detailed and visually appealing test reports, capturing various aspects of your test execution such as steps, attachments, and test results.
Generate Allure Reports
This feature allows you to generate Allure reports by annotating your Playwright tests with labels and steps. The code sample demonstrates how to add labels and steps to a basic test.
const { test } = require('@playwright/test');
const { allure } = require('allure-playwright');
test('basic test', async ({ page }) => {
allure.label('feature', 'Login');
allure.label('severity', 'critical');
await page.goto('https://example.com');
allure.step('Navigate to example.com');
await page.click('text=Login');
allure.step('Click on Login button');
// Add more steps and assertions
});
Attach Screenshots
This feature allows you to attach screenshots to your Allure reports. The code sample demonstrates how to take a screenshot during a test and attach it to the report.
const { test } = require('@playwright/test');
const { allure } = require('allure-playwright');
test('screenshot test', async ({ page }) => {
await page.goto('https://example.com');
const screenshot = await page.screenshot();
allure.attachment('Screenshot', screenshot, 'image/png');
});
Attach Logs
This feature allows you to attach logs to your Allure reports. The code sample demonstrates how to attach log data to the report.
const { test } = require('@playwright/test');
const { allure } = require('allure-playwright');
test('log test', async ({ page }) => {
await page.goto('https://example.com');
const logs = 'Some log data';
allure.attachment('Logs', logs, 'text/plain');
});
The jest-allure package integrates Allure reporting with Jest, another popular testing framework. It provides similar functionalities such as generating detailed test reports, attaching screenshots, and adding steps. However, it is specifically designed for use with Jest rather than Playwright.
The wdio-allure-reporter package integrates Allure reporting with WebdriverIO, a testing framework for Node.js. It offers similar functionalities such as generating test reports and attaching screenshots, but it is designed for use with WebdriverIO.
This project implements Allure integration with Playwright Test framework.
npm i -D @playwright/test allure-playwright
or via yarn:
yarn add @playwright/test allure-playwright --dev
Either add allure-playwright into playwright.config.ts:
{
reporter: "allure-playwright";
}
Or pass the same value via config file:
{
reporter: [["line"], ["allure-playwright"]];
}
Or pass the same value via command line:
npx playwright test --reporter=line,allure-playwright
Specify location for allure results:
Mac / Linux
ALLURE_RESULTS_DIR=my-allure-results npx playwright test --reporter=line,allure-playwright
Windows
set ALLURE_RESULTS_DIR=my-allure-results
npx playwright test --reporter=line,allure-playwright
Generate Allure Report:
allure generate my-allure-results -o allure-report --clean
Open Allure Report:
allure open allure-report
Some reporter settings can set by following options:
Option | Description | Default |
---|---|---|
outputFolder | Path to results folder. | ./allure-results |
detail | Hide pw:api and hooks steps in report. See below | true |
suiteTitle | Use test title instead of allure.suite() . See below | true |
const config = {
reporter: [
[
"allure-playwright",
{
detail: true,
outputFolder: "my-allure-results",
suiteTitle: false,
},
],
],
};
After exporting test results into Allure TestOps, the results may contain extra steps with Playwright’s API calls, as well as collisions in the name of the suits.
By default, each step of the test.step()
functions contains subsections Playwright’s API methods calls.
The report looks like:
> Before Hooks
> browserContext.newPage
> Open example.com
> page.goto( https://example.com/)
> Expect page text
> expect.toBeVisible
> After Hooks
> browserContext.close
To hide steps with Before / After hooks
and API calls page / expect / browser
set the option detail: false
By default, the reporter uses the test file path as the suite name.
If tests uses the allure.suite()
and it's value must be used in Allure TestOps custom fields, then set the option suiteTitle: false
Tests extra information can be provided by labels:
import { test, expect } from "@playwright/test";
import { allure } from "allure-playwright";
test("basic test", async ({ page }, testInfo) => {
await allure.label("labelName", "labelValue");
});
import { test, expect } from "@playwright/test";
import { allure } from "allure-playwright";
test("basic test", async ({ page }, testInfo) => {
await allure.link("https://playwright.dev", "playwright-site"); // link with name
await allure.issue("Issue Name", "https://github.com/allure-framework/allure-js/issues/352");
});
import { test, expect } from "@playwright/test";
import { allure, LabelName } from "allure-playwright";
test("basic test", async ({ page }, testInfo) => {
await allure.id("420");
});
import { test, expect } from "@playwright/test";
import { allure } from "allure-playwright";
test("basic test", async ({ page }, testInfo) => {
await allure.epic("Some Epic");
});
import { test, expect } from "@playwright/test";
import { allure } from "allure-playwright";
test("basic test", async ({ page }, testInfo) => {
await allure.story("Some Story");
});
import { test, expect } from "@playwright/test";
import { allure } from "allure-playwright";
test("basic test", async ({ page }, testInfo) => {
await allure.attachment("basic-page-screen", await page.screenshot(), {
contentType: "image/png",
});
});
import { test, expect } from "@playwright/test";
import { allure } from "allure-playwright";
export const TODO_ITEMS = ["buy some cheese", "feed the cat", "book a doctors appointment"];
test("basic test", async ({ page }, testInfo) => {
await allure.attachment("TODO_ITEMS", JSON.stringify(TODO_ITEMS), {
contentType: "application/json",
});
});
import { test, expect } from "@playwright/test";
import { allure } from "allure-playwright";
export const TODO_ITEMS = ["buy some cheese", "feed the cat", "book a doctors appointment"];
test("basic test", async ({ page }, testInfo) => {
await allure.step("Visit todolist page", async () => {
await page.goto("https://demo.playwright.dev/todomvc");
});
await allure.step("Create 1st todo.", async () => {
await page.locator(".new-todo").fill(TODO_ITEMS[0]);
await page.locator(".new-todo").press("Enter");
});
await expect(
page.locator(".view label"),
"Make sure the list only has one todo item.",
).toHaveText([TODO_ITEMS[0]]);
});
import { test, expect } from "@playwright/test";
import { allure } from "allure-playwright";
test("basic test", async ({ page }, testInfo) => {
await allure.parameter("parameterName", "parameterValue");
});
Also parameter takes an third optional parameter with the hidden and excluded options:
mode: "hidden" | "masked"
- masked
hide parameter value to secure sensitive data, and hidden
entirely hide parameter from report
excluded: true
- excludes parameter from the history
import { test, expect } from "@playwright/test";
import { allure } from "allure-playwright";
test("basic test", async ({ page }, testInfo) => {
await allure.parameter("parameterName", "parameterValue", { mode: "masked", excluded: true });
});
Allure allow you to execute only a subset of tests. This is useful when you want to run only a specific test or a group of tests.
To enable this feature, you need to add the following code to your playwright.config.js
:
+ import { testPlanFilter } from "allure-playwright/dist/testplan";
export default {
reporter: [
[
"allure-playwright",
],
],
projects: [
{
name: "chromium",
},
],
+ grep: testPlanFilter()
};
Allure will read ALLURE_TESTPLAN_PATH
environment variable and read testplan from the specified file.
Allure allows you to add environment information to the report. This is useful when you want to add some additional information to the report.
to enable this feature, you need to add the following field to your playwright.config.js
:
export default {
reporter: [
[
"allure-playwright",
{
+ environmentInfo: {
+ E2E_NODE_VERSION: process.version,
+ E2E_OS: process.platform,
+ },
},
],
],
};
Allure allows you to add visual comparisons to the report. This is useful when you want to add some additional information to the report.
import { test, expect } from "@playwright/test";
test("screendiff", async ({ page }) => {
await page.goto("https://playwright.dev/");
await expect(page).toHaveScreenshot();
});
If screenshots don't match, the report shows difference between them.
You also can pass allure metadata from test title.
This is useful when you need to set allureId for the tests with failing before hooks. Just add @allure.id={idValue}
for the allureId or @allure.label.{labelName}={labelValue}
for other types of labels.
import { test, expect } from "@playwright/test";
test("test with allureId @allure.id=256", async ({}) => {});
test("tst with severity @allure.label.severity=critical", async ({}) => {});
test("test with epic @allure.label.epic=login", async ({}) => {});
test("test with strangeLabel @allure.label.strangeLabel=strangeValue", async ({}) => {});
Warning Note that changing title can cause creating new testcases in history. To fix this please add
@allure.id={yourTestCaseId}
to the test name if you passing allure metadata from test title
FAQs
Allure Playwright integration
The npm package allure-playwright receives a total of 269,991 weekly downloads. As such, allure-playwright popularity was classified as popular.
We found that allure-playwright demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.