Skip to content

Instantly share code, notes, and snippets.

@mabenson00
Last active February 10, 2022 20:35
Show Gist options
  • Save mabenson00/899257efd68bdebbe896752c4792af48 to your computer and use it in GitHub Desktop.
Save mabenson00/899257efd68bdebbe896752c4792af48 to your computer and use it in GitHub Desktop.
Github Actions: Add failed test screenshots as artifacts

Upload failed test screenshots as Artifacts in Github Actions

If you're running your testing in CI through Github Actions and want to access the screenshots of the failed attempts, here's what you do. This assumes your tests are already set up to run in github actions

Find the path were your test runner is saving screenshots

Look at the the failed test logs in the Github action

Capybara Example: /home/runner/work/company/company/tmp/capybara/

     Capybara::ElementNotFound:
       Unable to find css "[role=\"unlock-button\"]"

     [Screenshot Image]: /home/runner/work/company/company/tmp/capybara/screenshots/failures_r_spec_example_groups_conflicts_of_interest_module_logged_in_conflicts_of_interest_table_with_records_can_finalize_conflicts_twice_716.png

Add the upload-artifact action directly after your test run step:

 - name: Run tests
        run: bundle exec rspec --pattern "spec/system/**/*_spec.rb"
      - name: Upload Artifacts
        if: failure()
        uses: actions/upload-artifact@v2
        with:
          name: screenshots
          path: /home/runner/work/themis/themis/tmp/capybara/screenshots/* 

if:failure() both makes sure that it only uploads the folder if there were test failures, and makes sure the failure doesn't skip the Upload Artifacts step

Download the artifacts on the summary page of your CI run

NOTE: There isn't a way to get github actions to upload individual file artifacts instead of a zip file

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment