Running a RobotFramework test on GitHub actions
Robot Framework is a versatile open-source automation framework that allows for easy automation of test cases, acceptance tests, and robotic process automation (RPA). Integrating Robot Framework into your CI/CD pipeline using GitHub Actions can streamline your testing process and ensure the reliability of your codebase. In this article, we’ll walk through the steps to set up and run Robot Framework tests on GitHub Actions.
Prerequisites
Before getting started, make sure you have the following prerequisites in place:
- A GitHub repository containing your Robot Framework tests.
- Robot Framework installed in your project. This can typically be achieved using tools like pip.
This is the sample code taken to run the test. In the sample code, I have added a test to search on Google for a country. This will be a simple test and I haven’t concentrated more on RobotFramework.
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${BROWSER} Chrome
${URL} https://www.google.com
*** Test Cases ***
Open Google Homepage and Search Countries Headlessly
Open Browser ${URL} ${BROWSER} options=add_argument("--headless")
Maximize Browser Window
Input Text name=q Afghanistan
Press Keys name=q ENTER
Sleep 2s # Wait for the search results to load
Capture Page Screenshot
[Teardown] Close Browser
*** Keywords ***
Set Browser Implicit Wait
[Arguments] ${timeout}
Set Selenium Implicit Wait ${timeout}Step 1: Create a GitHub Actions Workflow File
GitHub Actions are defined in YAML files stored in the .github/workflows directory in your repository. Create a new YAML file, for example, .github/workflows/robot-framework.yml.
name: Robot Framework Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Install dependencies
run: |
pip install robotframework-seleniumlibrary
- name: Run Robot Framework tests
run: |
robot --outputdir results/ tests/
- name: Test Report
uses: actions/upload-artifact@v4
with:
name: robot-framework-report
path: results/**This workflow will trigger on every push and pull request, checking out the repository, setting up Python, installing dependencies, and finally running Robot Framework tests located in the tests/ directory.
Step 2: Customize the Workflow
Installing Dependencies
Modify the requirements.txt file in your repository to include Robot Framework and any additional dependencies required for your tests.
robotframework==3.2.2Specifying Test Paths
Update the Run Robot Framework tests step in the workflow file to specify the correct paths for your Robot Framework tests.
- name: Run Robot Framework tests
run: |
robot tests/Customizing Robot Framework Execution
You can include additional flags or options for the Robot Framework execution by modifying the run command. For example:
- name: Run Robot Framework tests
run: |
robot --outputdir results/ tests/Step 3: Commit and Push
Commit the changes to your repository, including the new workflow file and any necessary updates. Push the changes to trigger the GitHub Actions workflow.
git add .
git commit -m "Add GitHub Actions workflow for Robot Framework"
git push origin masterStep 4: Monitor the Workflow Execution
Visit the “Actions” tab in your GitHub repository to monitor the workflow execution. You’ll be able to see the progress of each step and identify any issues that may arise during the Robot Framework test execution.
I have opened an execution in the GitHub action. In the execution, we can see the test steps. In the test, we have only one test on the project for testing purposes.
I have installed the dependencies of the test and used a docker image to run the tests. The docker image is old and has old libraries. If you guys want to use you can use the latest libraries and versions.
Artifacts are added as part of the yml and this will give the test reports on a storage on Github actions. We can specify multiple artifacts.
Reports can be downloaded on the server/machine. We can make a lot of changes to the yml.
That’s a wrap, this could help you guys build the test on the GitHub Actions pipeline.
I have created a project on GitHub and added the code here.
I have added the job of the GitHub Actions here.
Feel free to hit clap if you like the content. Happy Automation Testing :) Cheers. 👏
