A simple real-time chat room application built with Node.js, Socket.IO, and MongoDB, featuring comprehensive BDD testing with Cypress.
- User Authentication: Login with hardcoded credentials
- Real-time Messaging: Send and receive messages instantly
- Message History: View previous conversations
- Responsive Design: Modern, mobile-friendly interface
- User Status: See who's online and when users join/leave
- RESTful API: Login endpoint with JWT authentication
- WebSocket Support: Real-time communication via Socket.IO
- Database Integration: MongoDB for message persistence
- CORS Support: Cross-origin resource sharing enabled
- BDD Testing: Behavior-driven development with Gherkin syntax
- Cypress Integration: End-to-end testing framework with Cucumber
- Test Coverage: Comprehensive test scenarios for all user stories
- Professional Reports: Mochawesome HTML reports with pie charts and evidence
- Tag-based Execution: Run tests by tags (@smoke, @regression, @critical, etc.)
- Single Command Execution: Run tests, generate reports, and open in browser with one command
Before you begin, ensure you have the following installed:
- Node.js (v14 or higher)
- Docker (for MongoDB container)
- npm (comes with Node.js)
Note: This project uses MongoDB running in a Docker container, so you don't need to install MongoDB directly on your system.
For a quick setup, use the automated script:
# Make script executable
chmod +x setup.sh
# Run automated setup
./setup.shThis script will:
- Verify Node.js, npm, and Docker installation
- Install all dependencies
- Configure MongoDB Docker container
- Provide usage instructions and demo credentials
If you prefer manual setup, follow these steps:
# Update package list
sudo apt update
# Install Docker
sudo apt install -y docker.io
# Add your user to docker group (optional, to run without sudo)
sudo usermod -aG docker $USER
# Start Docker service
sudo systemctl start docker
sudo systemctl enable docker
# Verify installation
docker --version# Install Docker using the official script
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Start Docker service
sudo systemctl start docker
sudo systemctl enable docker
# Verify installation
docker --version# Install Docker Desktop from: https://www.docker.com/products/docker-desktop
# Or using Homebrew:
brew install --cask dockerDownload and install Docker Desktop from: https://www.docker.com/products/docker-desktop
# Navigate to project directory
cd chat-app
# Install dependencies
npm installThis project uses MongoDB running in a Docker container. Follow these steps:
# Check if MongoDB container exists and start it
docker start mongodb
# Verify it's running
docker ps | grep mongo# Run MongoDB in Docker container (this will download the image if needed)
docker run -d --name mongodb -p 27017:27017 mongo:latest
# Verify MongoDB is running
docker ps# Remove any existing container with the same name
docker rm mongodb
# Create and start the new MongoDB container
docker run -d --name mongodb -p 27017:27017 mongo:latest
# Check if it's running
docker ps | grep mongoCreate a docker-compose.yml file in the project root:
version: '3.8'
services:
mongodb:
image: mongo:latest
container_name: mongodb
ports:
- "27017:27017"
volumes:
- mongodb_data:/data/db
volumes:
mongodb_data:Then run:
# Start MongoDB with Docker Compose
docker-compose up -d
# Stop MongoDB
docker-compose down# Start the server
npm start
The backend will be available at http://localhost:5000
The frontend is served automatically by the backend at http://localhost:5000
Use these hardcoded credentials for testing:
| Username | Password |
|---|---|
| Ana | password123 |
| Juan | password456 |
| Charly | password789 |
Ensure the application and MongoDB are running before executing tests:
# Terminal 1: Start MongoDB Docker container
docker start mongodb
# Terminal 2: Start the application
npm start
# Terminal 3: Run tests (in a new terminal)
npm test# Run all tests in headless mode
npm test
# Run tests with Cypress GUI
npm run test:open
# Run tests in headless mode (alternative)
npm run test:headless# Run tests by specific tags
npm run test:smoke # Run @smoke tests
npm run test:regression # Run @regression tests
npm run test:critical # Run @critical tests
npm run test:chat # Run @chat tests
npm run test:login # Run @login tests
npm run test:multi-user # Run @multi-user tests
npm run test:basic # Run @basic tests
npm run test:api # Run @api tests
npm run test:backend # Run @backend tests
npm run test:authentication # Run @authentication tests# Execute tests, generate report, and open automatically
npm run test:smoke:auto # Run smoke tests with auto-report
npm run test:regression:auto # Run regression tests with auto-report
npm run test:critical:auto # Run critical tests with auto-report
npm run test:chat:auto # Run chat tests with auto-report
npm run test:login:auto # Run login tests with auto-report
npm run test:api:auto # Run API tests with auto-report
npm run test:backend:auto # Run backend tests with auto-report
npm run test:authentication:auto # Run authentication tests with auto-report
npm run test:all:auto # Run all tests with auto-report# Generate and open reports manually
npm run report # Generate Mochawesome report
npm run test:smoke:report # Run smoke tests and generate report
npm run test:regression:report # Run regression tests and generate reportcypress/
├── e2e/
│ └── features/ # BDD Feature files with tags
│ ├── login.feature # @login @authentication tags
│ ├── chat.feature # @chat @realtime @history tags
│ ├── multi-user.feature # @multi-user @critical tags
│ └── api.feature # @api @backend @authentication tags
├── support/
│ ├── commands.js # Custom commands
│ ├── e2e.js # Support file
│ └── step_definitions/
│ ├── all.steps.js # Frontend step definitions
│ └── api.steps.js # API step definitions
├── reports/
│ └── mochawesome-report/ # Mochawesome HTML reports
│ ├── merged-report.html # Main test report
│ ├── merged-report.json # Test data
│ ├── assets/ # Report assets (CSS, JS, fonts)
│ ├── screenshots/ # Failure screenshots
│ └── videos/ # Test execution videos
├── screenshots/ # Cypress screenshots
└── videos/ # Cypress videos
Login with existing credentials
- Valid login with correct username/password
- Invalid login with wrong credentials
- Empty field validation
Send and receive messages
- Send messages via button click
- Send messages via Enter key
- View message history
- Real-time message delivery
User interface
- Responsive design
- Message timestamps
- User status indicators
Accept login requests
- JWT token generation
- User authentication
- Session management
Reject invalid login requests
- Invalid credentials handling
- Error message responses
- Security validation
Store messages in database
- MongoDB integration
- Message persistence
- Real-time synchronization
-
login.feature: Tests user authentication scenarios
- Tags:
@login,@authentication,@smoke,@regression - Scenarios: Valid login, invalid credentials, empty fields
- Tags:
-
chat.feature: Tests messaging functionality
- Tags:
@chat,@realtime,@history,@smoke,@regression - Scenarios: Send messages, message history, real-time delivery
- Tags:
-
multi-user.feature: Tests multi-user interactions (COMMENTED - not executed)
- Tags:
@multi-user,@critical,@realtime,@regression - Scenarios: Multiple users, simultaneous messaging, user notifications
- Status: Commented out - not included in test execution
- Tags:
-
api.feature: Tests backend API functionality
- Tags:
@api,@backend,@authentication,@regression - Scenarios: Login API, message retrieval, WebSocket integration
- Tags:
- @smoke: Quick validation tests (2 scenarios)
- @regression: Full test suite (23 scenarios)
- @critical: High-priority tests (0 scenarios - multi-user commented)
- @chat: Chat functionality tests (7 scenarios)
- @login: Authentication tests (5 scenarios)
- @multi-user: Multi-user interaction tests (0 scenarios - commented)
- @api: Backend API tests (11 scenarios)
- @backend: Backend functionality tests (11 scenarios)
- @authentication: Authentication tests (16 scenarios)
- @basic: Basic functionality tests (12 scenarios)
The cypress.config.js file contains:
- Base URL configuration
- Viewport settings
- Timeout configurations
- Video and screenshot settings
- Mochawesome reporter configuration
- Cucumber preprocessor integration
The cypress-cucumber-preprocessor.config.js file contains:
- Step definitions path configuration
- Tag filtering settings
- JSON output configuration
- Message output settings
The framework generates professional HTML reports using Mochawesome with:
- 📊 Pie Charts: Visual representation of pass/fail percentages
- 📋 Detailed Results: Test-by-test breakdown with Gherkin steps
- 📸 Screenshots: Automatic capture on test failures
- 🎥 Videos: Full test execution recordings
- 🔍 Evidence: Integrated screenshots and videos in the report
- 📱 Responsive Design: Mobile-friendly report interface
After running tests, you'll find:
- HTML Report:
cypress/reports/mochawesome-report/merged-report.html - JSON Data:
cypress/reports/mochawesome-report/merged-report.json - Videos:
cypress/videos/- Test execution recordings - Screenshots:
cypress/screenshots/- Failure screenshots - Assets:
cypress/reports/mochawesome-report/assets/- Report styling and scripts
The framework uses a comprehensive tag system for flexible test execution:
- @smoke: Quick validation tests for basic functionality
- @regression: Complete test suite for full validation
- @critical: High-priority tests for core functionality
- @chat: Chat-specific functionality tests
- @login: Authentication and login tests
- @multi-user: Multi-user interaction tests
- @basic: Basic functionality tests
- @authentication: Authentication-related tests
- @realtime: Real-time messaging tests
- @history: Message history tests
@smoke @chat
Feature: Quick Chat Validation
Scenario: Send a message
Given I am logged in as "Ana"
When I type "Hello" in the message input
And I click the send button
Then I should see "Hello" in the chat
@regression @critical @multi-user
Feature: Multi-User Chat
Scenario: Multiple users can join and chat
Given user "Ana" is logged in
And user "Juan" is logged in
When Ana sends "Hi Bob!"
Then Juan should see "Hi Bob!"- Development: Use
@smokefor quick validation - Pre-deployment: Use
@criticalfor essential functionality - Full Testing: Use
@regressionfor complete validation - Feature Testing: Use specific tags like
@chator@login
-
MongoDB Connection Error
# Check if MongoDB Docker container is running docker ps | grep mongo # If container is not running, start it docker start mongodb # If container doesn't exist, create it docker run -d --name mongodb -p 27017:27017 mongo:latest # Check container logs for errors docker logs mongodb
-
Port Already in Use
# Kill process on port 5000 sudo lsof -ti:5000 | xargs kill -9
-
Cypress Tests Failing
# Ensure application is running curl http://localhost:5000 # Clear Cypress cache npx cypress cache clear
-
Permission Issues
# Fix MongoDB data directory permissions sudo chown -R $USER /data/db
Run tests in debug mode:
# Open Cypress GUI for debugging
npm run test:open
# Run specific test file
npx cypress run --spec "cypress/e2e/features/login.feature"- Create Feature File: Add
.featurefile incypress/e2e/features/- Use Gherkin syntax with Given/When/Then steps
- Add appropriate tags (@smoke, @regression, @critical, etc.)
- Implement Steps: Add step definitions in
cypress/support/step_definitions/all.steps.js - Add Tags to package.json: Update npm scripts for new tags if needed
- Test Execution: Use tag-based commands to run specific test suites
chat-app/
├── public/
│ └── index.html # Frontend application
├── cypress/ # AQA framework
│ ├── e2e/
│ │ └── features/ # BDD Feature files
│ │ ├── login.feature
│ │ ├── chat.feature
│ │ └── multi-user.feature
│ ├── support/
│ │ ├── commands.js # Custom commands
│ │ ├── e2e.js # Support file
│ │ └── step_definitions/
│ │ └── all.steps.js # Step definitions
│ ├── reports/
│ │ └── mochawesome-report/ # HTML reports
│ ├── screenshots/ # Test screenshots
│ └── videos/ # Test videos
├── server.js # Backend server
├── package.json # Dependencies & scripts
├── cypress.config.js # Cypress configuration
├── cypress-cucumber-preprocessor.config.js # Cucumber config
├── run-tests-and-open.js # Auto test runner
├── setup.sh # Automated setup script
└── README.md # This file
- Real-time Notifications: User join/leave notifications
- Message Persistence: All messages saved to database
- Responsive Design: Mobile-friendly interface
- Session Management: JWT-based authentication
- Error Handling: Comprehensive error messages
- Test Automation: Single-command test execution
- Professional Reports: Mochawesome HTML reports with charts and evidence
- Tag-based Testing: Flexible test execution by categories
- BDD Framework: Complete Cucumber integration with Cypress
- Auto Report Opening: Reports open automatically in browser
- Evidence Integration: Screenshots and videos embedded in reports
- Automated Setup: One-command setup script for quick installation
For issues or questions:
- Check the troubleshooting section above
- Verify all prerequisites are installed
- Ensure MongoDB is running
- Check that the application starts without errors
- Review test logs for specific error messages
✅ AQA Framework: Cypress with BDD support and Cucumber preprocessor
✅ Frontend: Modern, responsive chat interface
✅ Backend: Node.js with Socket.IO and MongoDB
✅ Database: Lightweight MongoDB setup
✅ Testing: Comprehensive test coverage with tag-based execution
✅ Reports: Professional Mochawesome HTML reports with evidence
✅ Documentation: Detailed setup instructions
✅ Automation: Single-command test execution with auto-report opening
✅ BDD Integration: Complete Gherkin feature files with step definitions
✅ Tag System: Flexible test execution by categories (@smoke, @regression, etc.)
✅ Setup Automation: One-command setup script for quick project initialization