Skip to content

Commit

Permalink
Use Cypress.io GitHub Action
Browse files Browse the repository at this point in the history
- These changes update the Cypress GitHub Workflow so that it will use the official Cypress GitHub Action for executing Cypress Tests. This will enable us to make use of caching, and standardises the approach across all of the other RSD services.
- I have also enabled the workflow_dispatch trigger so that Cypress tests can be run manually against a target environment
- Using a 'matrix' strategy will also enable us to test against multiple browsers in the future if we decide to do so
  • Loading branch information
DrizzlyOwl committed Dec 16, 2024
1 parent 99c8937 commit ae387b6
Showing 1 changed file with 41 additions and 17 deletions.
58 changes: 41 additions & 17 deletions .github/workflows/cypress-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ on:
concurrency:
group: ${{ github.workflow }}

env:
NODE_VERSION: 18.x

jobs:
cypress-tests:
name: Run Cypress Tests
if: inputs.environment == 'test' || inputs.environment == 'development'
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
strategy:
matrix:
browser: [
"edge"
]
container:
image: cypress/browsers:22.12.0
defaults:
run:
working-directory: Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.CypressTests
Expand All @@ -46,27 +49,48 @@ jobs:
with:
ref: ${{ github.ref }}

- name: Setup node.js
uses: actions/setup-node@v4
- name: Prepare Cypress cache
uses: cypress-io/github-action@v6
with:
node-version: ${{ env.NODE_VERSION }}

- name: Npm install
run: npm install
runTests: false
browser: ${{ matrix.browser }}
working-directory: Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.CypressTests

- name: Run cypress (dev)
- name: Run (dev)
if: inputs.environment == 'development'
run: npm run cy:run -- --env grepTags='-smoke',username=${{ secrets.USERNAME }},url=${{ secrets.AZURE_WEB_ENDPOINT }},api=${{ secrets.AZURE_API_ENDPOINT }},apiKey=${{ secrets.AZURE_API_KEY }},authKey=${{secrets.CYPRESS_TEST_SECRET}}
uses: cypress-io/github-action@v6
env:
CYPRESS_username: ${{ secrets.USERNAME }}
CYPRESS_grepTags: '-smoke'
CYPRESS_url: ${{ secrets.AZURE_WEB_ENDPOINT }}
CYPRESS_apiKey: ${{ secrets.AZURE_API_KEY }}
CYPRESS_authKey: ${{ secrets.CYPRESS_TEST_SECRET }}
with:
browser: ${{ matrix.browser }}
working-directory: Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.CypressTests
wait-on: ${{ secrets.AZURE_ENDPOINT }}
install: false

- name: Run cypress (test)
- name: Run (test)
if: inputs.environment == 'test'
run: npm run cy:smoke -- --env username=${{ secrets.USERNAME }},url=${{ secrets.AZURE_WEB_ENDPOINT }},api=${{ secrets.AZURE_API_ENDPOINT }},apiKey=${{ secrets.AZURE_API_KEY }},authKey=${{secrets.CYPRESS_TEST_SECRET}}
uses: cypress-io/github-action@v6
env:
CYPRESS_username: ${{ secrets.USERNAME }}
CYPRESS_url: ${{ secrets.AZURE_WEB_ENDPOINT }}
CYPRESS_apiKey: ${{ secrets.AZURE_API_KEY }}
CYPRESS_authKey: ${{ secrets.CYPRESS_TEST_SECRET }}
with:
browser: ${{ matrix.browser }}
working-directory: Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.CypressTests
wait-on: ${{ secrets.AZURE_ENDPOINT }}
spec: cypress/e2e/smoke/*
install: false

- name: Upload screenshots
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: screenshots-${{ inputs.environment }}
name: screenshots-${{ inputs.environment }}-${{ matrix.browser }}
path: Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.CypressTests/cypress/screenshots

- name: Generate report
Expand All @@ -79,7 +103,7 @@ jobs:
if: always()
uses: actions/upload-artifact@v4
with:
name: reports-${{ inputs.environment }}
name: reports-${{ inputs.environment }}-${{ matrix.browser }}
path: Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.CypressTests/mochareports

- name: Report results
Expand Down

0 comments on commit ae387b6

Please sign in to comment.