- Node.js: Ensure you have Node.js installed. Download Node.js here.
- Code Editor: Use an editor like Visual Studio Code (VSCode) for writing and managing your code.
Download and install Node.js from the Node.js Official Site.
Verify the installation by running the following commands:
node -v
npm -vCreate a new directory for your project and initialize a Node.js project:
mkdir cypress-automation
cd cypress-automation
npm init -yInstall Cypress as a development dependency:
npm install cypress --save-devRun the following command to open Cypress and complete the initial setup:
npx cypress openYour project should follow this folder structure:
cypress-automation/
├── cypress/
│ ├── constants/
│ ├── e2e/test.js
│ ├── fixtures/
│ └── support/
│ └── reports/
├── node_modules/
├── cypress.json
├── package.json
└── package-lock.json
Open cypress.json and add the following configuration to set up the Mochawesome reporter:
{
"reporter": "cypress-mochawesome-reporter",
"reporterOptions": {
"reportDir": "cypress/reports",
"overwrite": false,
"html": false,
"json": true
}
}Install the Mochawesome reporter to generate test reports:
npm install cypress-mochawesome-reporter --save-devAdd the following test scripts in your package.json:
"scripts": {
"cypress:open": "cypress open",
"cypress:run": "cypress run"
}To run tests using the Cypress Test Runner UI, use:
npm run cypress:openTo run tests in headless mode, use:
npm run cypress:runBelow is an example of setting up Cypress tests and generating reports using GitHub Actions:
name: Cypress Tests and Report
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
cypress-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install dependencies
run: |
npm install
npm install cypress --save-dev
- name: Install Cypress binary
run: npx cypress install
- name: Run Cypress tests and generate report
run: npm run cypress:run
- name: Upload Artifacts
if: always()
uses: actions/upload-artifact@v2
with:
name: Cypress-Artifacts
path: |
cypress/reports/**This setup ensures Cypress tests run automatically on each push or pull request to the main branch. The test reports are also generated and uploaded as artifacts.