When you begin with test automation, you may wonder how to run your tests automatically. A reliable way to do this is with GitHub Actions, which comes built into GitHub. Instead of executing scripts by hand, you can trigger them every time code is pushed, a pull request is created, or a scheduled time arrives.
In this blog, you will learn step by step how to set up GitHub Actions for test automation in clear and simple language.
What is GitHub Actions?
In simple terms, GitHub Actions is a feature that allows you to create workflows. A workflow is a set of instructions that GitHub follows. For example, it can install dependencies, run tests, build your code, or deploy applications.
Because of this, QA engineers and developers save valuable time. Tests run automatically without extra effort, which improves both speed and reliability.
Step 1: Create a Repository
To start, you need a GitHub repository for your project and automation scripts.
-
First, log in to GitHub.
-
Then, click on New Repository.
-
Next, choose a name such as
test-automation-demo
. -
Finally, upload your project files and test scripts.
Step 2: Add a Workflow File
After creating the repository, the next step is to define a workflow. Create a folder called .github/workflows
in your project. Inside it, add a file named test.yml
.
Here’s a simple workflow example:
name: Run Automation Tests
name: Run Automation Tests
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
– name: Checkout code
uses: actions/checkout@v3
– name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18
– name: Install dependencies
run: npm install
– name: Run tests
run: npm test
This workflow performs several tasks:
-
The workflow starts whenever you push or create a pull request on the
main
branch. -
By default, it runs on an Ubuntu server.
-
Next, Node.js is installed, although you can replace it with Java, Python, or another language.
-
Once the setup is complete, dependencies are installed.
-
Finally, the test scripts are executed.
Step 3: Push Code and Trigger Workflow
After saving the file, push your code to GitHub. As soon as you do, GitHub Actions automatically starts the workflow.
To monitor progress, open the Actions tab in your repository. There, you can select the latest run, view logs, and confirm whether the tests passed or failed.
Step 4: Customize for Your Framework
Every project is different, so the workflow may need updates.
-
With Java + Maven + TestNG, use
mvn test
. -
If you use Python + PyTest, run
pytest
. -
For Playwright, the command is
npx playwright test
.
Step 5: Add Reports (Optional)
In many projects, test reports are important. Fortunately, GitHub Actions allows you to upload them as artifacts. For instance, frameworks such as TestNG, JUnit, or Playwright can generate HTML or XML reports. You can then attach these reports so your team can review them later.
Benefits of GitHub Actions for Test Automation
There are several clear benefits of using GitHub Actions for test automation:
-
It saves time by running tests automatically.
-
Since it supports many languages, almost any framework will work.
-
Because everything runs in the cloud, heavy local setup is not required.
-
Moreover, it integrates smoothly into modern CI/CD pipelines.
Conclusion
To sum up, GitHub Actions for test automation is a simple yet powerful way to improve your QA process. With only one YAML file, you can run automated tests on every push or pull request.