As various projects I maintain for customers include end-to-end (E2E) tests using Playwright, which run on a daily schedule and on every new release, I wanted to automate following up on failed tests. Instead of manually creating issues, I automated the process using GitHub Actions and the GitHub API. This worked great, but I thought to myself, why not share this with the world? So, I created a GitHub Action that does exactly that.
![Sample issue created by the Playwright Issue Creator action](https://www.eliostruyf.com/uploads/2024/07/playwright-failed-test-issue.webp)
In this blog post, I will explain how you can use GitHub Action to create issues on failed Playwright tests automatically.
The GitHub Action
The GitHub Action is called Playwright Issue Creator and is available on the GitHub Marketplace.
The Playwright Issue Creator action relies on the JSON report created by the JSON reporter to verify the test results.
infoThe GitHub Action only creates an issue if there is no issue open with the following name
{prefix} {suite title} {test title} ({project})
. If one already exists, the extension adds a comment (can be turned on/off).
Usage
Include the JSON reporter to your Playwright config
As mentioned, the GitHub Action relies on the JSON report created by the JSON reporter.
You can include the JSON reporter in your Playwright config or use the --reporter json
flag when running your tests.
Using the JSON reporter in your Playwright config
|
|
Using the --reporter json
flag
|
|
Create a GitHub Action workflow
Create a new GitHub Action workflow in your repository and add the following content:
|
|
importantThe GitHub Action requires permissions to create issues, so you need to assign those permissions to your
GITHUB_TOKEN
.
tipAll the configuration options are explained on the Playwright Issue Creator page.
Run your tests
After you set up the above GitHub Action workflow, the test will run daily at 6 o’clock. You can, of course, add more triggers or run the tests on every push.
Happy testing!