How to generate allure reports in the Github Actions

Hi dear network, please help me I can’t found a possibility to generate allure reports in the Github actions. Please share your experience if somebody did it. Thanks.

This GitHub Actions yml file will use the macos-latest image which is currently pinned to 10.15 (11.x was taken out of the pool so it will NOT work.)

The mac container already has python 3.9, so the build script will say conditions are already satisfied.
I still like to have it anyway.

Then I install all the test dependencies and prefer to use pipenv.
Pipenv is installed system-wide on the container.

Brew has had updates that the macos-latest container does NOT have, so i manually run brew update.

brew will then install allure (system-wide). This is needed to use the allure CLI commands. You will see soon.

I create a temporary folder called ‘output’ that gets created at the project root. So it goes name-of-project/output/

I then run my tests. In this case here, I’m running firefox tests. You can have multiple jobs, one for each browser if you wish and they will run in parallel. I have a custom --browser command in my conftest.py file where i can pass in the browser (firefox in this case) and the driver will use firefox.
the --alluredir=/path/where/you/want/them/to/go is needed.

I have my allure-report folder going inside the temp output folder.
To recap, the path would be root/output/allure-report/allure json files here

make sure you are using working-directory so pytest collection can find your tests. This should be the name of your project at the root. So if your test project is called ‘bobs-tests’ you would put ‘bobs-tests’ here.

Here is where the magic happens. allure generate output/this is going to take those json files and turn it into a magical folder that includes an index.html file.

Now note, you would need to serve this index.html file to see your test results. You can’t just download the folder and click on index.html and expect it to work. The url would be file:///.... it needs to be something like localhost:1234. How does one do that?

Well first, let’s get the folder!
use the handy upload-artifact@v2 which will publish this folder as an artifact. This means you will get this item as a present after the build is done. You can download the artifact which is a zip file of the allure-report folder.

Now, how can you see the report?

You can drop that folder into an IDE with a built-in web service like intellij. If I drag this folder into Pycharm for example, right click index.html > open with > browser, I will see the fruits of my labor. A working allure report.

You can also publish your allure report to S3, GitHub Pages, etc as part of your github actions script. Up to you.

name: Python tests using allure example.

on:
  workflow_dispatch:
  schedule:
    - cron: '0 */4 * * *'

jobs:
  selenium_tests:

    runs-on: macos-latest

    steps:
      - uses: actions/checkout@v2
      - name: 🐍 Step 1 - Set up Python 3.9
        uses: actions/setup-python@v1
        with:
          python-version: 3.9
      - name: 🔗 Step 2 - Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install pipenv
          pipenv install --deploy --system
          brew update
          brew install allure
        working-directory: {name of your project root here}
      - name: 📂 Step 3 - Create a temp artifact folder named `output`
        run: |
          mkdir output
      - name: 🦊 Step 4 - Run Firefox tests and generate Allure folder inside `output` folder
        run: |
          pytest -vs tests/ --browser firefox --alluredir={provide the directory where you want the allure folder to go}
        working-directory: {name of your project root here}
      - name: 📊 Step 5 - Collect Allure files and generate allure-report folder
        run: |
          allure generate output/
      - name: 🎁 Step 6 - Publishing Allure artifact to GitHub Actions
        uses: actions/upload-artifact@v2
        with:
          name: allure-report
          path: allure-report

If you want to see the index.html report locally without the need of an IDE, you can download allure system-wide on your local machine.

Then $cd to where you put your allure report folder, and run allure serve /path/to/allure-results/

1 Like

Thanks a lot, I will try it