Skip to content

A robust testing framework built with Cypress, Cucumber, and TypeScript, providing a BDD approach to end-to-end testing for the SauceDemo e-commerce website with strong typing support.

Notifications You must be signed in to change notification settings

emanmhmd/cypress-cucumber-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Cypress Cucumber TypeScript Framework

A robust testing framework built with Cypress, Cucumber, and TypeScript, providing a BDD approach to end-to-end testing for the SauceDemo e-commerce website with strong typing support.

πŸ“‹ Features

  • βœ… BDD Testing - Use Gherkin syntax for human-readable tests
  • βœ… TypeScript Integration - Strong typing for better code quality and developer experience
  • βœ… Page Object Model - Organized, maintainable test structure
  • βœ… MochaAwesome Reports - Detailed HTML reports for test results
  • βœ… Custom Commands - Reusable Cypress commands for common operations and improved test readability

πŸ”§ Prerequisites

  • Node.js (v18.x or higher)
  • npm (v8.x or higher)
  • Git

🎬 Demo

demo.mp4

πŸš€ Getting Started

Clone the Repository

git clone https://github.com/emanmhmd/cypress-cucumber-ts.git
cd cypress-cucumber-ts

Install Dependencies

yarn install

πŸƒβ€β™‚οΈ Running Tests

Run All Tests

yarn test

Run Tests Step by Step

# 1. Install dependencies
yarn install

# 2. Run Cypress tests
npx cypress run

# 3. Verify reports exist
ls cypress/reports/mocha/*.json

# 4. Generate merged report
npx ts-node generateMochaReport.ts

Run Specific Feature

yarn test:feature --spec "cypress/e2e/features/auth.feature"

Run Tests in a Specific Browser

yarn test:chrome
yarn test:firefox
yarn test:edge

Open Cypress Test Runner

yarn cypress:open

πŸ“ Project Structure

cypress-cucumber-ts/
β”œβ”€β”€ cypress/
β”‚   β”œβ”€β”€ cucumber.json
β”‚   β”œβ”€β”€ e2e/
β”‚   β”‚   β”œβ”€β”€ features/           # Cucumber feature files
β”‚   β”‚   └── step_definitions/   # Step definitions for Cucumber
β”‚   β”œβ”€β”€ fixtures/
β”‚   β”‚   └── users.json          # Test data
β”‚   β”œβ”€β”€ reports/
β”‚   β”‚   β”œβ”€β”€ features/
β”‚   β”‚   β”œβ”€β”€ html/
β”‚   β”‚   └── mocha/              # MochaAwesome reports 
β”‚   β”œβ”€β”€ support/
β”‚   β”‚   β”œβ”€β”€ pages/              # Page Objects
β”‚   β”‚   β”œβ”€β”€ commands.ts         # Custom Cypress commands
β”‚   β”‚   └── e2e.ts              # Support file loaded before test files
β”‚   └── videos/                 # Test execution videos
β”œβ”€β”€ node_modules/
β”œβ”€β”€ reports/
β”œβ”€β”€ .gitignore
β”œβ”€β”€ cypress.config.ts           # Cypress configuration
β”œβ”€β”€ generateMochaReport.ts      # Report generation script
β”œβ”€β”€ package-lock.json
β”œβ”€β”€ package.json                # Project dependencies and scripts
β”œβ”€β”€ tsconfig.json               # TypeScript configuration
└── yarn.lock

πŸ“Š Reporting

This project uses MochaAwesome for generating test reports.

Reports Structure

cypress/
β”œβ”€β”€ reports/
β”‚   β”œβ”€β”€ html/              # HTML report output
β”‚   β”‚   └── index.html     # Main HTML report
β”‚   └── mocha/             # JSON report files

Generating Reports

Reports are automatically generated after test runs. To manually generate reports:

# Verify reports exist
ls cypress/reports/mocha/*.json

# Generate merged report
npx ts-node generateMochaReport.ts

# Open the generated report
open cypress/reports/mochareports/report.html

πŸ§ͺ Test Cases

This framework includes the following test scenarios:

Login and Logout

  • Verify that users can successfully log in with valid credentials
  • Verify that the system displays an error message with invalid credentials
  • Verify that locked out users cannot access the system
  • Verify that user redirected to products page after successful login
  • Verify that user with no permission can't add items to the cart
  • Verify that user can log out successfully
  • Verify that user can't access any page without login

Shopping Cart and Checkout Process

Shopping cart and Checkout functionality

  • Verify that user can add items to the cart
  • Verify that user can remove items from the cart
  • Verify that user can checkout successfully
  • Verify that user can't checkout without adding items to the cart
  • Verify that user can't checkout without login

Edge Cases

  • Verify that checkout form requires first name
  • Verify that checkout form requires last name
  • Verify that checkout form requires zip code

State Management

Cart State Management

  • Verify that cart remembers items when refreshing the page
  • Verify cart empties after order completes

πŸ“Ή Test Videos

Cypress automatically captures videos of test runs, which can be found in the cypress/videos directory after test execution.

Viewing Test Videos

# After running tests, videos will be available in the cypress/videos directory
open cypress/videos

Video Configuration

Video recording settings can be configured in the cypress.config.ts file:

// cypress.config.ts
export default defineConfig({
  e2e: {
    video: true,            // Enable/disable video recording
    videoCompression: 32,   // Compression quality (0-100)
    videosFolder: 'cypress/videos', // Videos output directory
  },
});

πŸ™ Acknowledgements

About

A robust testing framework built with Cypress, Cucumber, and TypeScript, providing a BDD approach to end-to-end testing for the SauceDemo e-commerce website with strong typing support.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published