Skip to content
View quanghaophan's full-sized avatar
🏠
Working from home
🏠
Working from home

Block or report quanghaophan

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Maximum 250 characters. Please don't include any personal information such as legal names or email addresses. Markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
quanghaophan/README.md

πŸš€ Selenium Test Automation Framework

TypeScript Selenium Mocha Node.js License Build Status Coverage Maintained

A comprehensive, enterprise-grade TypeScript-based Selenium automation testing framework implementing industry best practices for scalable and maintainable test automation.

🎯 Overview

This professional-grade automation framework is designed to test various functionalities of the-internet.herokuapp.com using modern testing approaches. Built with TypeScript, Selenium WebDriver 4.0, and Mocha/Chai, it demonstrates enterprise-level test automation practices including:

  • βœ… Page Object Model (POM) architecture
  • βœ… Behavior-Driven Development (BDD) approach
  • βœ… Cross-browser compatibility testing
  • βœ… Comprehensive logging and reporting
  • βœ… CI/CD ready configuration
  • βœ… Code quality enforcement

πŸš€ Key Features

  • TypeScript: Strongly-typed JavaScript for better code quality and IDE support
  • Page Object Model (POM): Separation of page elements and test logic for better maintainability
  • BDD Testing: Behavior-Driven Development approach using Mocha + Chai
  • Cross-browser Support: Configurable browser testing (Chrome, Firefox, Safari, Edge)
  • Comprehensive Logging: Detailed test execution logs for debugging and reporting
  • 5-second Static Waits: Manual verification pauses for visual confirmation during test execution
  • Modular Architecture: Reusable components and utilities

πŸ›  Technology Stack

Component Technology Version Purpose
Language TypeScript ^4.0.0 Main programming language
Test Framework Mocha ^9.0.0 Test runner and structure
Assertions Chai ^4.0.0 BDD-style assertions
Browser Automation Selenium WebDriver ^4.0.0 Web browser control
Runtime Node.js + ts-node ^10.0.0 TypeScript execution
Type Definitions @types/* Latest TypeScript type support

πŸ§ͺ Testing Approach

BDD (Behavior-Driven Development)

  • Human-readable tests: Tests written in natural language describing user behavior
  • Stakeholder collaboration: Tests that business users can understand
  • Given-When-Then structure: Clear test organization

Hooks for Test Lifecycle Management

  • before(): Browser setup and configuration
  • beforeEach(): Navigate to test pages and prepare test data
  • afterEach(): Clean up cookies and session data
  • after(): Browser teardown and resource cleanup

Page Object Model Benefits

  • Maintainability: Changes to UI require updates in only one place
  • Reusability: Page objects can be shared across multiple tests
  • Readability: Tests focus on business logic rather than technical details

πŸ“ Project Structure

selenium-test-project/
β”œβ”€β”€ πŸ“„ package.json                 # Node.js dependencies and scripts
β”œβ”€β”€ πŸ“„ tsconfig.json               # TypeScript configuration
β”œβ”€β”€ πŸ“„ README.md                   # Project documentation
└── πŸ“‚ src/                        # Source code directory
    β”œβ”€β”€ πŸ“‚ pages/                  # Page Object Models (POM)
    β”‚   β”œβ”€β”€ 🏠 BasePage.ts          # Base class for all page objects
    β”‚   β”œβ”€β”€ πŸ” LoginPage.ts         # Login functionality page object
    β”‚   β”œβ”€β”€ πŸ“‹ DropdownPage.ts      # Dropdown selection page object
    β”‚   β”œβ”€β”€ β˜‘οΈ CheckboxesPage.ts     # Checkbox interaction page object
    β”‚   β”œβ”€β”€ πŸ–±οΈ DragAndDropPage.ts   # Drag & drop functionality page object
    β”‚   β”œβ”€β”€ πŸ“€ FileUploadPage.ts    # File upload functionality page object
    β”‚   β”œβ”€β”€ 🎯 HoversPage.ts        # Mouse hover interactions page object
    β”‚   └── πŸ“ LoggingPage.ts       # Console logging page object
    β”œβ”€β”€ πŸ“‚ tests/                  # Test specifications
    β”‚   β”œβ”€β”€ πŸ§ͺ LoginTest.ts         # Login functionality tests
    β”‚   β”œβ”€β”€ πŸ§ͺ DropdownTest.ts      # Dropdown selection tests
    β”‚   β”œβ”€β”€ πŸ§ͺ CheckboxesTest.ts    # Checkbox interaction tests
    β”‚   β”œβ”€β”€ πŸ§ͺ DragAndDropTest.ts   # Drag & drop tests
    β”‚   β”œβ”€β”€ πŸ§ͺ FileUploadTest.ts    # File upload tests
    β”‚   β”œβ”€β”€ πŸ§ͺ HoversTest.ts        # Mouse hover tests
    β”‚   └── πŸ§ͺ LoggingTest.ts       # Console logging tests
    β”œβ”€β”€ πŸ“‚ utils/                  # Utility classes and helpers
    β”‚   β”œβ”€β”€ 🌐 WebDriverManager.ts  # Browser driver management
    β”‚   └── πŸ“Š Logger.ts            # Logging utility for test execution
    └── πŸ“‚ config/                 # Configuration files
        └── βš™οΈ TestConfig.ts        # Test environment configuration

πŸŽͺ Test Coverage

This framework covers the following test scenarios from the-internet.herokuapp.com:

Test Suite Page URL Test Scenarios Key Features Tested
Login Tests /login Valid/Invalid credentials, Error messages Form authentication, Security validation
Dropdown Tests /dropdown Option selection, Default values Select element interaction
Checkbox Tests /checkboxes Check/Uncheck operations Checkbox state management
Drag & Drop Tests /drag_and_drop Element positioning Mouse drag interactions
File Upload Tests /upload File selection and upload File handling capabilities
Hover Tests /hovers Mouse hover effects Dynamic content display
Logging Tests /javascript_error Console error capture Browser console monitoring

πŸš€ Quick Start

Prerequisites

  • Node.js (v14+ recommended)
  • npm or yarn package manager
  • Chrome Browser (or other supported browsers)
  • Git for version control

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd selenium-test-project
  2. Install dependencies:

    npm install
  3. Verify installation:

    npm run --version
    npx tsc --version

πŸ§ͺ Running Tests

Run All Tests

npm test

Run Specific Test Suite

# Run only login tests
npx mocha -r ts-node/register src/tests/LoginTest.ts

# Run only dropdown tests
npx mocha -r ts-node/register src/tests/DropdownTest.ts

Run Tests with Specific Browser

# Chrome (default)
BROWSER=chrome npm test

# Firefox
BROWSER=firefox npm test

# Safari
BROWSER=safari npm test

Run Tests in Headless Mode

HEADLESS=true npm test

πŸ“Š Test Execution Features

  • πŸ• 5-Second Static Waits: Each test includes manual verification pauses
  • πŸ“ Detailed Logging: Comprehensive test execution logs
  • πŸ”„ Automatic Cleanup: Browser sessions and cookies cleaned after each test
  • ⚑ Parallel Execution: Run multiple test suites simultaneously (coming soon)

πŸ”§ Configuration

Browser Configuration

Edit src/config/TestConfig.ts to customize:

export const TestConfig = {
  baseUrl: 'http://the-internet.herokuapp.com',
  browser: 'chrome',          // chrome, firefox, safari, edge
  headless: false,            // true for headless mode
  timeout: 30000,             // Element wait timeout
  implicitWait: 10000,        // Implicit wait time
  windowSize: '1920,1080'     // Browser window size
};

Test Data Management

  • Test data stored in page objects
  • Environment-specific configurations supported
  • Sensitive data can be stored in environment variables

πŸ“ Logging & Reporting

Built-in Logging System

The project includes a comprehensive logging utility (src/utils/Logger.ts) that captures:

  • βœ… Test execution steps
  • ⚠️ Warnings and errors
  • πŸ› Debug information
  • πŸ“Š Performance metrics
  • 🌐 Browser console logs

Log Levels

Logger.info('Test step completed');
Logger.warn('Element not found, retrying...');
Logger.error('Test failed with exception');
Logger.debug('Variable value: ' + value);

Test Reports

  • Console output with colored formatting
  • Detailed error messages with stack traces
  • Test execution time tracking
  • Browser console error capture

πŸ—οΈ Architecture Patterns

Page Object Model (POM)

// Example: LoginPage.ts
export class LoginPage extends BasePage {
  private usernameField = By.id('username');
  private passwordField = By.id('password');
  private loginButton = By.css('button[type="submit"]');

  async login(username: string, password: string): Promise<void> {
    await this.enterText(this.usernameField, username);
    await this.enterText(this.passwordField, password);
    await this.click(this.loginButton);
    
    // 5-second wait for manual verification
    await this.wait(5000);
  }
}

Test Structure (BDD Style)

// Example: LoginTest.ts
describe('Login Functionality', () => {
  describe('When user provides valid credentials', () => {
    it('should successfully log in and redirect to secure area', async () => {
      // Given: User is on login page
      await loginPage.navigate();
      
      // When: User enters valid credentials
      await loginPage.login('tomsmith', 'SuperSecretPassword!');
      
      // Then: User should be on secure page
      expect(await securePage.isDisplayed()).to.be.true;
      expect(await securePage.getWelcomeMessage())
        .to.contain('You logged into a secure area!');
    });
  });
});

🀝 Contributing

We welcome contributions! Please follow these guidelines:

Development Workflow

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/new-test-case
  3. Make your changes following TypeScript and testing best practices
  4. Add tests for new functionality
  5. Run the test suite: npm test
  6. Commit your changes: git commit -m "Add new test case for XYZ"
  7. Push to the branch: git push origin feature/new-test-case
  8. Create a Pull Request

Coding Standards

  • Follow TypeScript best practices
  • Use meaningful variable and function names
  • Add JSDoc comments for public methods
  • Maintain consistent indentation (2 spaces)
  • Write descriptive test names using BDD format

Adding New Test Cases

  1. Create page object in src/pages/
  2. Create test file in src/tests/
  3. Follow existing naming conventions
  4. Include 5-second static waits for manual verification
  5. Add comprehensive assertions

πŸ“š Learning Resources

Testing Concepts

  • BDD (Behavior-Driven Development): Write tests in natural language describing user behavior
  • TDD (Test-Driven Development): Write tests before implementing functionality
  • Page Object Model: Encapsulate page elements and actions in reusable classes
  • Hooks: Setup and teardown functions for test lifecycle management

Framework Documentation

πŸ“„ License

This project is licensed under the ISC License. See the LICENSE file for more details.

πŸ™‹β€β™‚οΈ Support

If you encounter any issues or have questions:

  1. Check the existing issues in the repository
  2. Create a new issue with detailed description
  3. Include error logs and environment information
  4. Tag the issue with appropriate labels

Happy Testing! πŸŽ‰

Built with ❀️ using TypeScript, Selenium WebDriver, Mocha, and Chai

Popular repositories Loading

  1. Hello-World Hello-World Public

    Learning using GIT

  2. quanghaophan quanghaophan Public

    Config files for my GitHub profile.

    TypeScript

  3. Assignment_07 Assignment_07 Public

    Python

  4. Assignment_08 Assignment_08 Public

    Python

  5. Assignment_09 Assignment_09 Public

    Jupyter Notebook

  6. Assignment_10 Assignment_10 Public

    Python