The setup presented in that blog post created multiple test reports, one for each shard.
The only downside with this, is that we didn't have an overview of all the tests, which made it a little bit harder to find a test report that you were looking for. For example, when a test failed you first needed to know the shard to open the corresponding test report.
Playwright v1.37.0 changes that by providing the ability to merge the different test reports into one.
The result is a beatiful looking pipeline, with one single test report as result thanks to the new merge-reports command.
Next, the reporter needs to be changed.
The reporter currently outputs the test results into an HTML file, but these cannot be combined into a single report.
Instead of exporting the test results into an HTML report, we want it to be a file format that can later be processed and merged.
To update the reporter, modify the reporter within the playwright config to create a blob instead of an html file.
With this change the output directory containing the test result files is also different, and is changed from playwright-report to blob-report.
This results in a zip file containing a JSON file with the test output.
playwright.config.ts
import type {PlaywrightTestConfig} from "@playwright/test";
constconfig:PlaywrightTestConfig={
reporter:process.env.CI?'blob':'html',
}
playwright.config.ts
import type { PlaywrightTestConfig } from "@playwright/test";
const config: PlaywrightTestConfig = {
reporter: 'html',
reporter: process.env.CI ? 'blob' : 'html',
}
The change above only makes use of the blob format in a continuous integration environment (using the environment variable process.env.CI), in other words within your build pipeline.
You can also enable this for your local environment if that's desired, e.g. when you're also making use of test sharding when running your test suite locally.
To create a HTML test report the last step is to merge the different blob files.
Luckily we don't need to do this manually, but we can use the new merge-reports command.
Pass it the location where your blob files are located.
Now that we got that working, it's time to update our pipeline and make the above changes to it.
Beause the output of the test results is changed to blob-report, we need to update the artifact upload step.
A side note: while updating the step, you can also lower the retention time because these files will be replaced by the single output file that will be created next.
This change still results in multiple output files.
To merge the files we use the merge-reports command in an additional job.
This job downloads all the blob reports created by the sharded jobs, which all upload their individual reports as an artifact.
This needs to be an extra job because the test shards are run in parallel, each in its own isolated environment.
playwright.yml
create-report:
name:๐ Create test report
if:always()
# import to wait until all the test jobs have finished
needs:[test]
runs-on:ubuntu-latest
steps:
-uses:actions/checkout@v3
-uses:actions/setup-node@v3
-name:Install dependencies
run:npm ci
-name:Download blob reports from GitHub Actions Artifacts
uses:actions/download-artifact@v3
with:
name:all-blob-reports
path:all-blob-reports
-name:Merge into HTML Report
run:npx playwright merge-reports --reporter html ./all-blob-reports