A Cypress test automation framework designed for multi-environment testing with support for UI and API testing.
Application under test: https://www.saucedemo.com/
- Multi-Environment Support: Separate configurations for Dev, QA, and Production environments
- Cross-Browser Testing: Chrome, Edge, and WebKit support
- GitHub Actions CI: Automated test execution on push with parallel browser matrix
- Cypress Cloud Integration: Cloud recording and dashboard for test results and analytics
- HTML Test Reports: Beautiful, interactive Mochawesome HTML reports with embedded screenshots for failed tests
- Test Organization: Structured test suite with UI and API
- Tag-Based Test Filtering: Run specific test suites using tags (@smoke, @qa, @ui, etc.)
- Page Object Model: Maintainable test structure with reusable page objects
- API Testing: Built-in API testing capabilities
- Code Quality: ESLint and Prettier configuration for consistent code style
- Node.js: v16 or higher
- npm: v7 or higher
- Git: For version control
- Clone the repository:
git clone <repository-url>
cd cypress-framework- Install dependencies:
npm install- Set up environment variables:
cp cypress.env.json.dist cypress.env.json- Edit
cypress.env.jsonwith your credentials:
{
"CYPRESS_RECORD_KEY": "your-cypress-cloud-key",
"username": "standard_user",
"password": "secret_sauce"
}- Update Cypress Cloud Project ID:
- Open
cypress.config.js - Replace
projectId: "YOUR ID HERE"with your actual Cypress Cloud project ID - Get your project ID from Cypress Cloud Dashboard
- Open
cypress-framework/
βββ .github/
β βββ workflows/
β βββ main.yml # GitHub Actions CI workflow
βββ cypress/
β βββ e2e/
β β βββ api/ # API test specifications
β β βββ ui/ # UI test specifications
β βββ fixtures/ # Test data files
β βββ support/
β β βββ commands.js # Custom Cypress commands
β β βββ e2e.js # Global configuration
β β βββ page-objects/ # Page Object Models
β β βββ utils.js # Utility functions
βββ github-workflows-examples/ # Example GitHub Actions workflows
β βββ matrix-browsers.yml # Browser matrix example
β βββ matrix-custom-run-commands.yml # Matrix with Custom npm scripts example
βββ cypress.config.js # Base Cypress configuration
βββ dev.config.js # Development environment config
βββ qa.config.js # QA environment config
βββ prod.config.js # Production environment config
βββ eslint.config.js # ESLint configuration
βββ package.json # Project dependencies and scripts
npm run cy:open # Open Cypress Test Runner
npm run cy:run # Run tests in headless modenpm run dev:open # Open Test Runner for Dev
npm run dev:run # Run all tests on Dev
npm run dev:run:chrome # Run on Chrome browser
npm run dev:run:edge # Run on Edge browser
npm run dev:run:webkit # Run on WebKit browsernpm run qa:open # Open Test Runner for QA
npm run qa:run # Run all tests on QA
npm run qa:run:smoke # Run smoke tests only
npm run qa:run:chrome # Run on Chrome browser
npm run qa:run:edge # Run on Edge browser
npm run qa:run:webkit # Run on WebKit browsernpm run prod:open # Open Test Runner for Production
npm run prod:run # Run all tests on Production
npm run prod:run:chrome # Run on Chrome browser
npm run prod:run:edge # Run on Edge browser
npm run prod:run:webkit # Run on WebKit browsernpm run qa:run:chrome:cloud # Run Chrome tests with cloud recording
npm run qa:run:edge:cloud # Run Edge tests with cloud recording
npm run qa:run:webkit:cloud # Run WebKit tests with cloud recordingnpm run lint # Run ESLint on test files
npm run format # Format code with PrettierTests can be filtered using tags. Example tags:
@smoke- Critical smoke tests@ui- UI tests@api- API tests
Run specific tagged tests:
npm run qa:run:smoke # Run only smoke tests
npx cypress run --env grepTags=@ui # Run UI tests onlyEach environment has its own configuration file that extends the base cypress.config.js:
- Base URL: Automatically set per environment
- API Base URL: Separate API endpoint configuration
- Viewport: 1920x1080 default viewport
- Retries: 1 retry in run mode, 0 in open mode
- Timeouts:
- Page Load: 20 seconds
- Command: 15 seconds
{
viewportWidth: 1920,
viewportHeight: 1080,
experimentalMemoryManagement: true,
experimentalWebKitSupport: true,
chromeWebSecurity: false,
watchForFileChanges: false,
retries: { "openMode": 0, "runMode": 1 }
}This framework includes:
- cypress-mochawesome-reporter: Beautiful HTML test reports
- @bahmutov/cy-grep: Test filtering by tags
- @bahmutov/cy-api: Enhanced API testing
- cypress-plugin-steps: Step-by-step test reporting
- @4tw/cypress-drag-drop: Drag and drop support
- cypress-real-events: Real browser events
- cypress-if: Conditional testing
- cypress-recurse: Retry logic for flaky tests
describe('Sample UI Test', { tags: ['@regression', '@ui'] }, () => {
beforeEach(() => {
cy.visit('/')
})
it('Should perform login', { tags: ['@smoke'] }, () => {
cy.get('[data-test="username"]').type('user')
cy.get('[data-test="password"]').type('pass')
cy.get('[data-test="login-button"]').click()
})
})describe('API Tests', { tags: ['@api'] }, () => {
it('Should create a resource', () => {
cy.api({
method: 'POST',
url: '/api/endpoint',
body: { data: 'value' }
}).then((response) => {
expect(response.status).to.eq(201)
})
})
})This framework uses cypress-mochawesome-reporter to generate beautiful HTML test reports.
Report Features:
- Interactive HTML reports with test results
- Embedded screenshots for failed tests
- Inline assets for easy sharing
- Browser-specific report directories
Report Locations:
- HTML Reports:
cypress/reports/mochawesome-{browser}-{date}/ - Screenshots:
cypress/reports/screenshots/ - Videos:
cypress/reports/videos/ - Downloads:
cypress/downloads/
Reports are automatically generated after each test run with browser and date information in the folder name.
This framework includes automated CI/CD pipeline with GitHub Actions:
Features:
- Automated test execution on every push
- Parallel browser matrix (Electron, Chrome)
- Cypress Cloud recording with test results dashboard
- Automatic dependency caching for faster builds
Workflow Configuration:
The workflow is defined in .github/workflows/main.yml and runs tests across multiple browsers in parallel.
Sample Workflows:
Check the github-workflows-examples/ folder for additional workflow examples:
matrix-browsers.yml- Example of browser matrix strategymatrix-custom-run-commands.yml- Example using custom npm scripts in matrix
Required GitHub Secrets:
Add these secrets in your GitHub repository (Settings β Secrets and variables β Actions β Repository secrets):
CYPRESS_USERNAME- Test user usernameCYPRESS_PASSWORD- Test user passwordCYPRESS_RECORD_KEY- Cypress Cloud recording key (get from Cypress Dashboard)
View Results:
- GitHub Actions: Check the Actions tab in your repository
- Cypress Cloud: Visit Cypress Cloud Dashboard to view detailed test results, screenshots, and videos
- Use
cy.debug()to pause test execution - Use
cy.pause()to pause in interactive mode - Enable Chrome DevTools for inspection
- Review screenshots and videos in the reports folder
- Follow the existing code style
- Run
npm run lintbefore committing - Run
npm run formatto format code - Tag tests appropriately
- Update documentation as needed
Add these to your cypress.env.json:
{
"CYPRESS_RECORD_KEY": "your-key",
"username": "standard_user",
"password": "secret_sauce",
}- Never commit
cypress.env.jsonto version control - Use
.envfiles for sensitive data - Rotate credentials regularly
- Use CI/CD secrets for cloud recording keys
Issue: Tests failing due to timeout
Solution: Increase timeout in configuration or use cy.wait() strategically
Issue: WebKit tests failing
Solution: Ensure injectDocumentDomain=true is set and playwright-webkit is installed
Issue: Cloud recording not working
Solution: Verify CYPRESS_RECORD_KEY is set correctly and projectId is configured
Issue: ESLint errors
Solution: Run npm run format and fix remaining issues manually