GitHub Actions lets you run tasks automatically when you change your code. Integrating Cypress means you can test your website every time you update it, without doing it by hand.
GitHub Actions integration in Cypress
name: Cypress Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- run: npm install
- run: npx cypress runThis is a basic GitHub Actions workflow file in YAML format.
It runs Cypress tests on every push or pull request automatically.
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm install
- run: npx cypress runon:
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm ci
- run: npx cypress runjobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache node modules
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
- run: npm ci
- run: npx cypress runThis workflow runs Cypress tests on every push or pull request. It checks out the code, sets up Node.js version 18, installs dependencies cleanly, and runs Cypress tests.
name: Cypress Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- run: npm ci
- run: npx cypress runMake sure your project has a valid package.json with Cypress listed as a dependency.
You can customize the Node.js version in the setup step to match your project needs.
Check GitHub Actions logs to see detailed test results and errors if tests fail.
GitHub Actions can run Cypress tests automatically on code changes.
This helps catch bugs early and saves manual testing time.
Workflows are defined in YAML files inside your project's .github/workflows folder.