Repository navigation
Description
🚀 Feature Request
The JUnit reporter writes name and classname on each <testcase>, but not file. CI systems read file to find the source file of each test:
- GitLab MR test report widget: https://docs.gitlab.com/ci/testing/unit_test_reports/ (shows
fileas the test's file path, and "Copy failed test names" requires it, so failed tests can be rerun locally) - CircleCI test splitting by timings: https://circleci.com/docs/guides/optimize/parallelism-faster-jobs/ (needs "the
fileattribute, either on the<testsuite>or<testcase>tag")
classname is relative to the config's testDir, so it cannot be used instead when testDir is not the repository root.
Proposal: two new JUnit reporter options.
| Option | Env var | Default | Description |
|---|---|---|---|
addFileAttribute |
PLAYWRIGHT_JUNIT_ADD_FILE_ATTRIBUTE |
false |
Write a file attribute on each <testcase>. |
fileRoot |
PLAYWRIGHT_JUNIT_FILE_ROOT |
config folder | The folder that file is relative to. |
file=path.relative(fileRoot, test.location.file), with forward slashes on every OS.fileRootresolves likeoutputFile/outputDir: the env var wins and resolves against the current working folder; the option resolves against the config folder.- With the config at the repository root,
addFileAttribute: trueis enough. In a monorepo with one config per package,fileRoot(orPLAYWRIGHT_JUNIT_FILE_ROOT=$CI_PROJECT_DIRfor every package) gives the repository-relative path. I raised the same gap in Vitest: Add afileTemplateoption to the JUnit reporter vitest-dev/vitest#11852 merge-reports --reporter junitcannot pass reporter options, so merge users set the env vars, or leave out--reporterand list the reporter with its options in the merge config (-c). The defaultfileRootis then the merge config's folder, or the current working folder without-c.- When
addFileAttributeis off, the output does not change.
Prior art: the Vitest and jest-junit JUnit reporters both have an addFileAttribute option, default off.
- Vitest: https://vitest.dev/guide/reporters (added in feat(reporter): support
includeConsoleOutputandaddFileAttributein junit vitest-dev/vitest#5659) jest-junit: https://github.com/jest-community/jest-junit, which also hasfilePathPrefix, "Useful in case of monorepo".
Alternatives considered:
- A fixed prefix or template (like
filePathPrefix, or thefileTemplateproposed for Vitest). A prefix must be set for each package. A base folder covers the same case with one value: an env var set to the repository root works for every package, at any depth. - Always write
file, with no option. This changes the output for every user, and the other runners keep it opt-in.
Example
Config at the repository root:
// playwright.config.ts
export default defineConfig({
testDir: './e2e',
reporter: [['junit', { outputFile: 'results.xml', addFileAttribute: true }]],
});A failure in e2e/auth/login.spec.ts produces:
<testcase name="logs in" classname="auth/login.spec.ts" file="e2e/auth/login.spec.ts" time="1.2">One config per package in a monorepo:
// packages/foo/playwright.config.ts
export default defineConfig({
testDir: './src',
reporter: [['junit', { outputFile: 'results.xml', addFileAttribute: true, fileRoot: '../..' }]],
});A failure in packages/foo/src/auth/login.spec.ts produces:
<testcase name="logs in" classname="auth/login.spec.ts" file="packages/foo/src/auth/login.spec.ts" time="1.2">Motivation
Today, users who want file paths in GitLab or CircleCI must post-process the JUnit XML to add file, and in monorepos also add the package path. With these options, Playwright's JUnit output would work with these CI tools without extra scripts.
Activity
[-][Feature]:[/-][+][Feature]: JUnit reporter: add a `file` attribute to `<testcase>`[/+][-][Feature]: JUnit reporter: add a `file` attribute to `<testcase>`[/-][+][Feature]: JUnit reporter option to add a `file` attribute to `<testcase>`[/+]pranav-sirnapalli commentedon Nov 13, 2026
Hi, I'd be interested in working on this feature. I can implement the opt-in
addFileAttributeandfileRootoptions, including environment variable support and regression tests for relative paths, Windows compatibility, and backward compatibility.Would this be open for a community contribution? I'm happy to work on it if approved.
microsoft-playwright-automation commentedon Nov 13, 2026
microsoft-playwright-automation commentedon Nov 13, 2026
Hi, I'm the Playwright bot and I checked the reporter and the cited CI requirements.
The
fileattribute is missing in current Playwright, and neither proposed option exists. On1.66.0-next(0ad21f1d34e40a51649a97e14da787172d68d073), both direct JUnit output and merged blob reports omit it, even withaddFileAttribute: true. GitLab and CircleCI document the attribute for the uses described here.#40231 proposed adding
file, but closed without merging. The maintainer's response identifies the same path-base and Windows separator concerns that this proposal addresses. This needs a public API decision: whether to add a configurable source-path root, with two permanent reporter options and matching environment variables. I have not introduced that API or proposed a PR.Acceptance check and results
I extended the existing
should render expectedtest locally, using:With a passing test named
oneine2e/a.test.js, both direct and merged reports produce:The test first verifies today's
classnameand absentfile, then marks the requested assertion as expected to fail:On Linux at the commit above:
npm ci --no-audit --no-fundandnpm run buildsucceeded.should render expectedchecks passed for direct and merged reports.Command:
npm run ttest -- reporter-junit --grep 'should render expected' --workers=1. These checks use no browser. Windows path normalization andfileRootbehavior were not runtime-tested because those options are not implemented.The source, public types and reporter documentation contain no existing equivalent. Vitest and jest-junit both document an opt-in
addFileAttribute; Vitest's linked PR, vitest-dev/vitest#5659, merged. This confirms prior art, not an existing Playwright solution.Triaged on Linux by the Playwright bot - agent run
feat(junit): add fileRoot option for the file attribute