An open API service indexing awesome lists of open source software.

https://github.com/emanmhmd/cypress-cucumber-ts

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.
https://github.com/emanmhmd/cypress-cucumber-ts

bdd cucumber cyperss framework mochawesome page-object-model reporting test-automation test-framework testing typescript yarn

Last synced: 8 days ago
JSON representation

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.

Awesome Lists containing this project

README

          

# 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](https://www.saucedemo.com) 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

https://github.com/user-attachments/assets/2d53c33c-0b25-457c-9ad7-0673e04ca8ab

## ๐Ÿš€ Getting Started

### Clone the Repository

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

### Install Dependencies

```bash
yarn install
```

## ๐Ÿƒโ€โ™‚๏ธ Running Tests

### Run All Tests

```bash
yarn test
```

### Run Tests Step by Step

```bash
# 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

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

### Run Tests in a Specific Browser

```bash
yarn test:chrome
yarn test:firefox
yarn test:edge
```

### Open Cypress Test Runner

```bash
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:

```bash
# 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

```bash
# 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:

```typescript
// 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

- [Cypress Documentation](https://docs.cypress.io/)
- [Cucumber Documentation](https://cucumber.io/docs/cucumber/)
- [TypeScript Documentation](https://www.typescriptlang.org/docs/)
- [Cypress Cucumber Preprocessor](https://github.com/badeball/cypress-cucumber-preprocessor)