This Github action enables you to take the screenshots and videos generated by Cypress after a test run and upload them directly to a Slack channel of your choice. All files are contained within a single message thread to minimize noise.
Required – Slack app token. See Slack's documentation. To get a token:
- Create an app
- Request scopes for
files:write,chat:writeandchannels:read - Install the app into your workspace
- Invite the bot to whatever channel you want to send the videos and screenshots to
/invite <botname>or@botname - Grab the
Bot User OAuth Tokenfrom theOAuth & Permissionspage - Add that token as a secret to your Github repo's
Actions Secretsfound underSettings -> Secrets and variables -> Actions(in the examples below we call itSLACK_TOKEN)
Required – Slack channel to upload to.
Optional – The folder where Cypress stores screenshots on the build machine.
Default: cypress/screenshots
Note
If your project uses Cypress from the project root folder, the default value will work for you. But if your project uses Cypress in a subfolder (like most monorepos), you'll need to provide the relative path to that folder (i.e. app/tests/e2e/cypress/screenshots).
The relative path for the default value resolves to /home/runner/work/<REPO_NAME>/<REPO_NAME>/cypress/screenshots
(Don't include a trailing slash on your path!)
Optional – The folder where Cypress stores videos on the build machine.
Default: cypress/videos
Optional – Custom Slack message for when the screenshots and videos have been uploaded.
Default: A Cypress test just finished. I've placed the screenshots and videos in this thread. Good pie!
Optional – What to upload: "both", "screenshots", or "videos".
Default: both
both- Upload both screenshots and videos (default behavior)screenshots- Upload only screenshotsvideos- Upload only videos
on: [pull_request]
env:
SLACK_CHANNEL: 'general'
jobs:
test-and-upload-results-on-fail:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: 'Run tests'
uses: cypress-io/github-action@v2
- name: 'Upload screenshots and videos to Slack'
uses: trymbill/cypress-slack-video-upload-action@v2.1.1
if: failure()
with:
token: ${{ secrets.SLACK_TOKEN }}
channel: ${{ env.SLACK_CHANNEL }}
message-text: 'Cypress tests failed! They have been placed in this thread, good luck.'on: [push]
env:
SLACK_CHANNEL: 'general'
jobs:
test-and-upload-results:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: 'Run tests'
uses: cypress-io/github-action@v2
- name: 'Upload screenshots and videos to Slack'
uses: trymbill/cypress-slack-video-upload-action@v2.1.1
with:
token: ${{ secrets.SLACK_TOKEN }}
channel: ${{ env.SLACK_CHANNEL }}on: [pull_request]
env:
SLACK_CHANNEL: 'general'
jobs:
test-and-upload-screenshots-only:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: 'Run tests'
uses: cypress-io/github-action@v2
- name: 'Upload only screenshots to Slack'
uses: trymbill/cypress-slack-video-upload-action@v2.1.1
if: failure()
with:
token: ${{ secrets.SLACK_TOKEN }}
channel: ${{ env.SLACK_CHANNEL }}
uploadType: 'screenshots' # Options: 'both', 'screenshots', or 'videos'This repository includes a test setup to verify the action works correctly.
-
Build, lint and package the action:
npm run all
-
Run Cypress tests:
# Run all tests npm run cypress:run # Run specific test npx cypress run --spec cypress/e2e/passing.cy.js npx cypress run --spec cypress/e2e/failing.cy.js # Open Cypress UI (for interactive testing) npm run cypress:open
-
Test the Slack upload action locally:
# After running a failing test, you can test the action manually # @actions/core reads from INPUT_* environment variables when running locally INPUT_TOKEN=your_token INPUT_CHANNEL=your_channel node dist/main.js # Optional: specify screenshotsDir, videosDir and custom message INPUT_TOKEN=your_token INPUT_CHANNEL=your_channel INPUT_SCREENSHOTSDIR=cypress INPUT_VIDEOSDIR=cypress INPUT_MESSAGE_TEXT="Test message" node dist/main.js
The repository includes a GitHub Actions workflow (.github/workflows/test.yml) that:
- Runs on pull requests
- Executes both passing and failing Cypress tests
- Verifies the Slack upload action completes successfully