Photo by Praveen Thirumurugan on Unsplash

Test Automation 101: (6) Running Robot Framework in GitHub Actions

Vince Reyes Tech

--

Our Robot Framework Project is almost complete. We have established a folder structure containing the required resources and test cases. We have the code pushed into a remote repository.

But how can we further improve our test automation project?

Imagine a scenario where the number of test cases is increasing. We have an extensive test suite that we need to execute for product releases. If we rely on our local machine to run all the test cases, it will consume a lot of time, and we won’t be able to utilize that time on other productive tasks. In this scenario, GitHub Actions come in.

We can execute our test suite remotely and automatically based on different triggers with GitHub Actions.

Before we proceed, since I wrote this tutorial series for beginners, this topic might take a lot of work to absorb fully. To make it easier, I’ll share the code I wrote for executing tests in GitHub actions. Our focus is for you to experience running your tests remotely. So it’s okay if you don’t understand the deeper details for now.

Going back to the main discussion, here’s what you need to do to run tests in GitHub Actions:

Step 1: Create a new YML file in your existing project

In Visual Studio Code, create the same folder structure in the image below and add a new file called “ci.yml.”

Add the following code to the file:

name: CI

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Web Application
run: docker run -d -p 8000:8000 vncrtech/puppybank

- name: Setup Python
uses: actions/setup-python@v5.0.0
with:
python-version: 3.12.2

- name: Setup Workspace
run: |
python -m venv .venv
source .venv/bin/activate
pip install --upgrade robotframework-seleniumlibrary

- name: Run Tests
run: $GITHUB_WORKSPACE/.venv/bin/python3.12 -m robot.run --suite test-automation-101-rf.tests.smoke.login --outputdir $GITHUB_WORKSPACE/results .

- name: Upload Test Report
uses: actions/upload-artifact@v4.3.1
with:
name: rf-results
path: results/

You may also visit my repo for reference: vncrtech/test-automation-101-rf (github.com)

Step 2: Commit and push the file

In Source Control, move the file to Staged Changes

Add a commit message, and then click “Commit & Push.”

Step 3: Go to GitHub Actions and trigger your test

Go to the Actions tab and then click CI under Workflows.

Click “Run workflow.”

You should see a screen similar to the one below. You can click “build” to see the job’s steps.

You should see something similar to this:

You should see a green checkmark on the build job to indicate it is successful.

If you go back to the previous screen once the job is complete, you should be able to see an artifact containing the test results.

That’s it! Let’s do a recap.

What did the job do?

  1. Deploy the Web Application to be tested.
  2. Install the required software and libraries.
  3. Run the tests.
  4. Publish the results.

If you revisit the ci.yml file, you will see that each step has an equivalent code. I recommend exploring the GitHub Marketplace for Actions to see what other commands you can do.

I included this article for you to have in an intro to CI/CD, which is a much bigger topic.

For now, if you have successfully followed the tutorial series up to this point, then that calls for a celebration. Congratulations!

This article is the final installment of our Test Automation 101 series, using Robot Framework. I really hope that it has been helpful for you and that it has ignited your interest in learning more. If you found it valuable, why not share it with a friend or on social media? It would mean a lot to me. Thanks for tuning in!

--

--