TL;DR
This article covers how to split a growing Playwright suite across several TeamCity agents with shard builds and merge their blob reports into one HTML report tab and one Tests tab. It also covers the snapshot and artifact dependencies, the CI variable and the timeouts that decide whether the merge works.
Run N shard builds plus one merge build that runs npx playwright merge-reports to merge the shards' blob reports into a single report.
- Give the merge build a snapshot dependency on each of the three shard builds. Set each snapshot dependency to run the merge build even when that shard fails.
- In the merge build, run
npx playwright merge-reports --reporter=html all-blob-reports.
Your Playwright suite runs on one TeamCity agent, and we'd expect the build to get longer with every test you add. Adding workers looks like the fix. The Playwright docs recommend workers: 1 on CI instead, for stability and reproducibility, so that each test gets the machine's full resources (Playwright CI docs). On one agent with workers set to 1, tests run sequentially, one at a time.
The way out is more agents. Playwright can split a suite into shards, and in a CI pipeline each shard can run as its own job on its own hardware. On TeamCity, each of those jobs is a build running on its own agent.
Splitting is the easy half. Each shard writes its own report, and you have to merge them to see the whole run. Skip the merge, and a three-shard run leaves you three partial reports and no single list of what passed, failed or retried.
What you want is N shard builds plus one merge build that runs npx playwright merge-reports to merge the shards' blob reports into a single report. Run with the html reporter, the merge produces a standard HTML report in the playwright-report directory.
When to shard on TeamCity
Shard when one agent takes longer than your team is willing to wait for a build. Each shard then runs as a separate TeamCity build on its own agent, and each agent you add brings its own CPU to the run. We compare that with adding workers in when to scale beyond one machine.
Check what Playwright splits before you count agents. Playwright can shard only tests that can run in parallel, so by default it shards whole test files (Playwright sharding docs). Without fullyParallel, Playwright assigns entire test files to shards, though the same file may go to different shards across different projects. The shard that gets the largest file can't finish until every test in that file has run.
Don't shard a suite that already finishes quickly on one agent. Each shard has its own test report, and getting one combined report with the results from all the shards means merging them. A short suite gives little back for that extra step.
TeamCity's Parallel Tests build feature is the other option you'll come across. Use --shard builds instead. Playwright's sharding docs show one workflow that runs the tests on several machines in parallel and then merges the reports into a single report. In a CI pipeline, each shard can run as a separate job.
CI-aware Playwright config
One environment variable decides how every shard runs. The config in Playwright's sharding docs uses the blob reporter when CI is set and the HTML reporter otherwise, and the config below also uses that check to set retries and the worker count.
If the config specifies no reporter, Playwright uses the dot reporter when the CI environment variable is set and the list reporter otherwise. The dot reporter keeps a TeamCity build log short. The --reporter option takes a comma-separated list of reporters. Unlike --reporter, --add-reporter keeps the configured reporters instead of replacing them. Pass --reporter=dot,blob in the shard command if you want progress in the log as well as the zip.
Anti-pattern
Assuming the agent sets CI
The config branches on process.env.CI, and the TeamCity build runs it with a plain npx playwright test --shard=1/3 without ever setting CI. Every shard takes the local branch. It writes an HTML report instead of a blob, so the merge build has nothing to merge.
// Anti-pattern: nothing in the TeamCity build sets CI, so every shard takes the 'html' branch
import { defineConfig } from '@playwright/test';
export default defineConfig({
testDir: './tests',
reporter: process.env.CI ? 'blob' : 'html',
});
Fix
Set CI yourself, on every shard build and on the merge build. In TeamCity, add a parameter named env.CI with the value true to each build configuration. A secret such as an API token goes in the same parameter list, as a Password parameter. Don't assume the agent sets CI, and don't rewrite the config to check TEAMCITY_VERSION instead. Keep the one variable the docs' config reads.
With CI set, this config gives every shard what it needs:
// playwright.config.ts
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests',
// Blob zips on CI for merge-reports, an HTML report for local runs
reporter: process.env.CI ? 'blob' : 'html',
// One worker per agent on CI, as the Playwright CI docs recommend
workers: process.env.CI ? 1 : undefined,
// Retries are off unless you turn them on
retries: process.env.CI ? 2 : 0,
use: {
trace: 'on-first-retry',
},
projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }],
});
Failing tests are not retried by default. With retries on, Playwright retries a failing test until it passes or reaches the maximum number of retries. The docs say to record traces on CI with trace: 'on-first-retry', which produces a trace.zip for every test that was retried, so each flaky test comes with a recording of its retry.
Shard build configurations
Every shard build is the same build with a different number. Create one build configuration per shard (three in these examples) and give each a parameter named shard, set to 1, 2 or 3. Then give each one a Command Line step that installs dependencies and runs npx playwright test --shard=%shard%/3 --reporter=blob. TeamCity replaces %shard% with the parameter's value, so the three configurations differ in that one parameter. Share one build template across all three so they don't drift apart.
Naming blob on the command line, on top of the config's switch, pins the shard's output to what the merge build expects. The blob reporter writes its zip to blob-report in the directory that holds package.json (Playwright reporter docs). With sharding on, the file is named report-<hash>-<shard_number>.zip, so the zips from three shards never clash.
Publish only those zips as the shard build's artifacts, with this artifact path rule:
blob-report/*.zip => blob-report
A blob report holds every test that ran, its results and its attachments, traces and screenshot diffs included. Since the blob report already contains all test attachments, traces and screenshot diffs included, we'd leave test-results out of the artifacts.
Anti-pattern
Stale zips on a reused agent
On a persistent agent, the shard step runs in a working directory that earlier builds already used. In Playwright 1.64 the blob reporter kept old reports with other names in its output folder, so merge-reports could pick up stale zips (#43161); Playwright 1.65 again deletes the content of the output directory before writing the report (Playwright 1.65 release notes). On Playwright 1.64, clear that folder yourself.
# Anti-pattern: on Playwright 1.64, blob-report can still hold zips from earlier builds on this agent
npm ci
npx playwright install --with-deps
npx playwright test --shard=%shard%/3 --reporter=blob
Fix
Delete the folder before the tests run, so the only zips left to publish are this build's:
npm ci
npx playwright install --with-deps
# Playwright 1.64 left zips from earlier runs in blob-report
rm -rf blob-report
npx playwright test --shard=%shard%/3 --reporter=blob
Snapshot and artifact dependencies
The merge build is only as good as the zips it receives. To merge the shards' reports, Playwright's docs say to put the blob report files into a single directory, for example all-blob-reports. TeamCity's two kinds of dependency handle that.
Give the merge build a snapshot dependency on each of the three shard builds. The four builds then form one chain: they run against the same revision, and triggering the merge build queues the shards it depends on.
Set each snapshot dependency to run the merge build even when that shard fails. The docs' CI example merges reports after the test jobs even if some shards have failed. A red shard is exactly the run you need a report for.
Then add one artifact dependency per shard build, taking artifacts from the build in the same chain. Where those artifacts land is the part that goes wrong.
Anti-pattern
One subfolder per shard
Giving each shard's artifacts their own folder under all-blob-reports looks tidy. But merge-reports reads the blob reports from the directory you pass it, and the docs say to put all the blob files into that single directory. In one Azure Pipelines report (#31550), merge-reports answered "No report files found" even though the shard artifacts had downloaded to the path. A maintainer closed the issue because they lacked the information to act on it. Check the layout on disk yourself before you suspect Playwright.
# Anti-pattern: each shard's zips land in a subfolder, not in all-blob-reports itself
blob-report/*.zip => all-blob-reports/shard-1
blob-report/*.zip => all-blob-reports/shard-2
blob-report/*.zip => all-blob-reports/shard-3
Fix
Give all three artifact dependencies the same rule, so every zip lands directly in all-blob-reports:
blob-report/*.zip => all-blob-reports
The file names carry the shard number, so the three sets sit side by side without overwriting each other.
Merging shard reports
One command turns those zips into the report people open. npx playwright merge-reports reads every blob report in the directory you pass and merges them into a single report (Playwright sharding docs). The merge build's Command Line step needs the project's dependencies and the shards' blob reports in all-blob-reports:
npm ci
npx playwright merge-reports --reporter=html all-blob-reports
The html reporter writes a standard HTML report to playwright-report. Publish that folder with this artifact path rule, then add a report tab in the project settings with playwright-report/index.html as its start page, so the merged report opens inside TeamCity:
playwright-report => playwright-report
--reporter takes several reporters separated by commas, so the same merge can write junit or json output for other tools next to the HTML report. Once those reporters need options, move them into a merge-only config and pass it with --config. That file can differ from the config the shards ran with, which keeps output settings out of the test run:
// merge.config.ts: read by merge-reports only, never by the shard builds
import { defineConfig } from '@playwright/test';
export default defineConfig({
// The tests root that file paths in the merged report resolve against
testDir: './tests',
reporter: [['html'], ['json', { outputFile: 'results.json' }]],
});
npm ci
npx playwright merge-reports --config=merge.config.ts all-blob-reports
The testDir line matters once shards run on different operating systems. When you merge reports from different operating systems, the docs require an explicit merge config that says which directory is the tests root.
Tests tab results
The report tab shows the run to anyone who opens it, but TeamCity itself still has no list of the tests that ran. TeamCity reads service messages, log lines such as ##teamcity[testStarted name='checkout'], and lists each reported test in the build's Tests tab. You don't need a package to print them. A custom reporter is a class that implements some of the reporter methods (Playwright reporter docs), and our guide to building a custom reporter maps the hooks if you want to extend this one.
This one waits for the end of the run and prints one block of messages per test:
// teamcity-reporter.ts: prints TeamCity service messages for every test in the run
import type {
FullConfig,
FullResult,
Reporter,
Suite,
TestCase,
} from '@playwright/test/reporter';
// Service message values escape | ' [ ] and line breaks with a leading |
function escape(value: string): string {
return value
.replace(/\|/g, '||')
.replace(/'/g, "|'")
.replace(/\[/g, '|[')
.replace(/\]/g, '|]')
.replace(/\n/g, '|n')
.replace(/\r/g, '|r');
}
function message(type: string, attributes: Record<string, string | number>): void {
const body = Object.entries(attributes)
.map(([key, value]) => `${key}='${escape(String(value))}'`)
.join(' ');
console.log(`##teamcity[${type} ${body}]`);
}
class TeamCityReporter implements Reporter {
private rootSuite: Suite | undefined;
onBegin(_config: FullConfig, suite: Suite): void {
this.rootSuite = suite;
}
// Report once per test, after every retry has finished
onEnd(_result: FullResult): void {
for (const test of this.rootSuite?.allTests() ?? []) this.report(test);
}
private report(test: TestCase): void {
const name = test.titlePath().filter(Boolean).join(' > ');
const last = test.results[test.results.length - 1];
if (!last || test.outcome() === 'skipped') {
message('testIgnored', { name, message: 'skipped' });
return;
}
message('testStarted', { name });
if (test.results.length > 1) {
// Keep earlier attempts visible, so a pass on retry is never silent
const attempts = test.results.map((result) => {
const trace = result.attachments.some((a) => a.name === 'trace');
return `attempt ${result.retry + 1}: ${result.status}${trace ? ' (trace in the report tab)' : ''}`;
});
message('testStdOut', { name, out: attempts.join('\n') });
}
if (test.outcome() === 'unexpected') {
message('testFailed', { name, message: last.error?.message ?? last.status });
}
message('testFinished', { name, duration: last.duration });
}
}
export default TeamCityReporter;
The reporter sends each test's final result, which is what the Tests tab should count. A test that failed and then passed on retry is reported as passed, but its earlier attempts go into the test's output, with a note on every attempt that recorded a trace. With trace: 'on-first-retry', that is the first retry. The blob report carries the trace with the test's other attachments, and blob reports can be merged and converted to any other Playwright report, so you find it in the merged report like any sharded run's trace. Whether a test that passed on retry should fail the build is your call; we'd keep it green, keep its attempts visible and fix it from the trace.
You could install a TeamCity reporter package from npm instead. Owning a reporter this short beats depending on someone else's release schedule for it.
Anti-pattern
Service messages in every shard
Adding the reporter to each shard's command looks like the shortest path to a full Tests tab. Each shard build then lists only the tests it ran, and the whole run never appears in one place.
Fix
Run the reporter once, in the merge build. merge-reports reads all blob reports from the directory you pass and merges them into a single report, so the reporter receives every test from every shard. The merge build's Tests tab then holds the whole run:
npm ci
npx playwright merge-reports --reporter=html,./teamcity-reporter.ts all-blob-reports
Checking the build chain
Test the chain on your laptop before you build it in TeamCity. --reporter=blob makes each shard write a blob report, by default into the blob-report directory.
rm -rf blob-report all-blob-reports
mkdir all-blob-reports
CI=true npx playwright test --shard=1/2 --reporter=blob
mv blob-report/*.zip all-blob-reports/
CI=true npx playwright test --shard=2/2 --reporter=blob
mv blob-report/*.zip all-blob-reports/
ls all-blob-reports
npx playwright merge-reports --reporter=html all-blob-reports
npx playwright show-report
Move each zip out before the next shard runs: the blob reporter deletes the existing content of its output directory before it writes a new report. Open the merged report and check that tests from both shards are in it. If one shard's tests are missing here, the problem is in your files or your config, because TeamCity isn't involved yet.
Once the chain exists in TeamCity, run three checks:
- Add a throwaway test that fails on its first attempt and passes on the retry. The merged HTML report should mark the test as flaky, with a trace for the retry. The Tests tab should list the test with the failed attempt in its output.
- Break a test so that one shard goes red. If the merge build runs, the merged report includes the failure, because a blob report contains all the tests that were run and their results.
- Run the chain twice on the same agents and confirm that the second report holds only the second run's tests.
Gotchas after the first run
The first green run proves the wiring, and the next problems show up in the timings. By default, Playwright assigns entire test files to shards, so the number of tests per file can greatly influence shard distribution. When test files are uneven in size, some shards may run many more tests than others, while others may run fewer or even none.
Test-level sharding narrows the gap. When your tests can run in parallel at the test level, each shard balances the number of individual tests it runs, and the docs call that the preferred mode for even load. In that mode, Playwright splits the work based on the total number of tests, so we'd expect a shard that draws a cluster of slow tests to still finish last. Balanced Sharding in Currents keeps the same --shard builds but has each shard fetch recent spec-file durations and split the tests so the shards finish at about the same time.
Merge paths
If the merge build finds no report files at all, check the artifact dependency rules first: every zip has to sit directly in all-blob-reports. Unresolved file paths or missing code snippets in the merged report point somewhere else. Shards that ran on different operating systems need an explicit merge config that names the tests root, which is the testDir line in merge.config.ts. Shards that ran with several configs, each with its own test directory, are harder. A user asked Playwright to support merging reports with multiple test directories, such as from multiple configs (#39855). The issue was closed as not planned. The reporter said that, in their monorepo, they could instead use a top-level config with projects. Move to one config with projects before you shard a monorepo.
Anti-pattern
No global timeout
Leaving the run unbounded and trusting the build's execution timeout feels safe. By default a Playwright run has no upper bound, so a shard that hangs runs until TeamCity kills it. A run killed by the CI provider's job limit does not produce a test report. That shard publishes no blob zip, and its tests drop out of the merged report without a failure to show for them.
// Anti-pattern: no global timeout, so a hung shard runs until TeamCity kills it
import { defineConfig } from '@playwright/test';
export default defineConfig({
testDir: './tests',
reporter: process.env.CI ? 'blob' : 'html',
workers: process.env.CI ? 1 : undefined,
retries: process.env.CI ? 2 : 0,
use: { trace: 'on-first-retry' },
});
Fix
The CI docs say to always set a global timeout in CI. Set globalTimeout below the shard build's execution timeout, so a hung run ends on Playwright's limit instead of TeamCity's:
import { defineConfig } from '@playwright/test';
export default defineConfig({
testDir: './tests',
reporter: process.env.CI ? 'blob' : 'html',
workers: process.env.CI ? 1 : undefined,
retries: process.env.CI ? 2 : 0,
// 50 minutes: below the 60-minute execution timeout set on the shard builds
globalTimeout: process.env.CI ? 50 * 60 * 1000 : undefined,
use: { trace: 'on-first-retry' },
});
Where native merging stops
The merge build turns every shard's blob report into a single HTML report. The chain also gives you one Tests tab per run. The price is that the shard count now lives in TeamCity. A fourth shard means another build configuration, another snapshot and artifact dependency, and /3 changed to /4 in every shard command. Each of those is one more place for the merge to break.
The merge build exists only because each shard writes its own report. Reporting in CI in Currents collects every shard build's results into one run when all of them share a CI Build ID, so you don't need a merge build or its artifact dependencies; without a shared ID, each shard shows up as a separate run.
Until the shard count changes often, the native chain is all you need: one shard template, one merge build, and CI set on every build in the chain.
Frequently asked questions
How do I run Playwright tests on TeamCity across several agents?
Shard the suite: Playwright can split a suite into shards, and in a CI pipeline each shard can run as its own job on its own hardware. One merge build then runs npx playwright merge-reports to merge the shards' blob reports into a single report. The shard builds are set up in shard build configurations.
How do I merge Playwright shard reports in TeamCity?
Run npx playwright merge-reports in the merge build. It reads every blob report in the directory you pass and merges them into a single report. With the html reporter, the merge produces a standard HTML report in the playwright-report directory, as merging shard reports describes.
How should I set up TeamCity artifact dependencies for Playwright blob reports?
Put every shard's blob report files into a single directory, such as all-blob-reports, and not into one subfolder per shard. merge-reports reads the blob reports from the directory you pass it, and the docs say to put all the blob files into that single directory, as the subfolder anti-pattern explains.
Why does Playwright merge-reports find no report files?
Check the artifact dependency rules first: every zip has to sit directly in all-blob-reports. merge-reports reads the blob reports from the directory you pass it, so zips in subfolders don't count. Unresolved file paths or missing code snippets in the merged report point somewhere else, as merge paths covers.
Should the TeamCity merge build run when a Playwright shard fails?
Yes. Set each snapshot dependency to run the merge build even when that shard fails, since the docs' CI example merges reports after the test jobs even if some shards have failed. A red shard is exactly the run you need a report for, as snapshot and artifact dependencies explains.
Do I need a global timeout for Playwright on TeamCity?
Yes. The CI docs say to always set a global timeout in CI, so set globalTimeout below the shard build's execution timeout, and a hung run ends on Playwright's limit instead of TeamCity's. A run killed by the CI provider's job limit does not produce a test report, as the global timeout anti-pattern shows.




