Side Quest 1 - Running Tests in CI
Using Github for CI/CD
We want to be able to run our tests in a consistent environment and to share the results with the rest of the team.
To this end, we can use Github Actions to:
- Detect commits
- Run our tests against our web application
- Capture any artifacts (e.g. the test report)
Hosting our web application
We want our web application hosted so that it can be navigated to by the Github CI runner at a consistent url.
Netlify allows us to host a web application build from code in a Github repo.
Any commits to the application code will trigger a rebuild and redeploy on Netlify.
We can create a project in Netlify and link it to our web application repo.
Then open Build & deploy settings and set these values in Build settings
| Setting | Value |
|---|---|
| Build Command | CI=false npm run build |
| Publish Directory | build |
Give the Netlify project a name, e.g. stc-job-portal from which it will create a url.
Run Deploy and the application will be hosted at stc-job-portal.netlify.app:
Creating a Github Action
We need to run tests in headless mode, so we update serenity.conf:
serenity.test.root = com.softwaretestingcentre.testjobportal.features
webdriver {
capabilities {
"goog:chromeOptions" {
args = ["headless=chrome"]
}
}
}
And create a Github Action to run the tests and save the report whenever we commit to the test project:
name: Test Job Portal
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 23
uses: actions/setup-java@v4
with:
java-version: '23'
distribution: 'temurin'
cache: maven
- uses: browser-actions/setup-chrome@latest
- run: chrome --version
- name: Run Serenity Tests
run: mvn clean verify
- name: Test Report Generation
uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: Serenity Report # Name of the folder
path: target/site/serenity/ # Path to test results
Now our tests will run against the hosted web application whenever we push changes to the Github test repo:
And we have captured the test report: