How to setup CI GitHub action to run robot framework
GitHub Actions is a platform that enables you to automate and manage software development workflows. These workflows are defined using YAML files and can be triggered by various events, such as code pushes, pull requests, or scheduled intervals. Each workflow consists of one or more jobs, which in turn contain a series of steps. These steps can perform actions like building, testing, deploying, and more.
Why Use GitHub Actions:
Automation: GitHub Actions automates repetitive tasks in your software development process, saving time and reducing human error.
CI/CD Integration: It seamlessly integrates continuous integration (CI) and continuous deployment (CD) directly into your repository, making it easier to build, test, and deploy your code.
How to set up GitHub action?
Setting up a GitHub Actions workflow to run Robot Framework involves creating a .yml
file in your repository's .github/workflows
directory. This file will define the workflow steps, including installing dependencies, running tests, and reporting the results. Here's a basic example of how you can set up a GitHub Actions workflow to run Robot Framework tests:
Go to your GitHub repository. You can notice that you have a new tab called Actions:
Step 1: Click on the Actions tab and New Workflow button as following.
Step 2: Select Python package template.
- when you save a
.github/workflows
directory and will create a workflow YAML file: Inside the.github/workflows
directory, create a.yml
file. You can name it something likerobot-framework.yml
. - Define the workflow in the YAML file: Edit the
.yml
file you created and define the workflow using the following structure:
name: Robot Framework CI
on:
push:
branches:
- master
pull_request:
workflow_dispatch:
jobs:
Run-Test:
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v1
- uses: actions/cache@v2
id: cache
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirement.txt') }}
- name: Install pip dependencies
run: |
pip install --upgrade pip
pip install -r requirement.txt
- name: Run Test
run: python -m robot --outputdir results testcases/functional_tests
- name: Run Test and create report
run: python -m robot -d reports -x junit-report.xml "testcases/functional_tests"
- name: Run Robot Framework tests and generate report
run: |
echo "ROBOT_RC=$?" >> "$GITHUB_ENV"
# - name: If Auto Test Pass Rate Not 100%, Job Will Fail
# if: env.ROBOT_RC != '0'
# run: |
# echo "Auto Test Pass Rate Not 100%, Please Check Test Result"
# exit 1
- name: Publish test results
uses: actions/upload-artifact@v2
with:
name: robot-test-results
path: results
- Customize paths and settings: Modify the paths, versions, and other settings as needed based on your repository’s structure and requirements.
- Commit and push: After creating and configuring the workflow YAML file, commit and push it to your repository.
- GitHub Actions Workflow: GitHub will automatically detect the new workflow configuration and start running it whenever changes are pushed to the specified branch (in this case,
main
). You can also manually trigger the workflow from the "Actions" tab in your repository.
Remember that this is a basic example, and you can customize the workflow to match your specific needs. You might want to add steps for sending notifications, generating reports, or integrating with other tools.
Additionally, ensure that your Robot Framework tests are structured properly, and any necessary dependencies are listed in the requirements.txt
file or similar. The example workflow assumes you have your tests in .robot
files and that you're using Python for your Robot Framework installation. If you're using a different setup, you'll need to adjust the workflow accordingly.