Skip to content

This repository demonstrates web automation using Jest for testing and TypeScript for development. It includes test automation scripts for web applications, focusing on testing the functionality and user interactions in the browser.

Notifications You must be signed in to change notification settings

adityadwic/jest-typescript-web-automation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

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

Repository files navigation

πŸ§ͺ Jest Web Automation Framework

A comprehensive, production-ready web automation testing framework built with Jest, TypeScript, and Selenium WebDriver, following industry best practices and Page Object Model (POM) design pattern.

πŸš€ Features

  • βœ… Complete End-to-End Testing - Full user registration flow automation (18 test steps)
  • βœ… TypeScript Support - Strong typing for better code quality and maintenance
  • βœ… Page Object Model - Scalable and maintainable test architecture
  • βœ… Modern Reporting - Multiple report formats with beautiful HTML dashboards
  • βœ… Screenshot Capture - Automatic screenshots on test failures
  • βœ… Cross-Browser Ready - Chrome optimized with extensible browser support
  • βœ… CI/CD Ready - Configured for continuous integration pipelines
  • βœ… Code Quality Tools - ESLint, Prettier for consistent code standards

πŸ› οΈ Tech Stack

Core Framework

Testing & Automation

  • ChromeDriver 139.x - Chrome browser automation
  • Page Object Model - Design pattern for maintainable tests
  • Custom Test Reporter - Enhanced logging and step tracking

Development Tools

Reporting & CI/CD

  • jest-html-reporters - HTML test reports
  • jest-junit - JUnit XML reports
  • Custom HTML Dashboard - Interactive test execution summary
  • JSON Reports - Machine-readable test results

πŸ“ Project Structure

β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ __tests__/              # Test files
β”‚   β”‚   └── user-registration.test.ts
β”‚   β”œβ”€β”€ pages/                  # Page Object Model classes
β”‚   β”‚   β”œβ”€β”€ home.page.ts
β”‚   β”‚   β”œβ”€β”€ login.page.ts
β”‚   β”‚   β”œβ”€β”€ signup.page.ts
β”‚   β”‚   β”œβ”€β”€ account-created.page.ts
β”‚   β”‚   └── account-deleted.page.ts
β”‚   β”œβ”€β”€ utils/                  # Utility classes
β”‚   β”‚   β”œβ”€β”€ base.page.ts        # Base page class
β”‚   β”‚   β”œβ”€β”€ test-reporter.ts    # Custom reporting
β”‚   β”‚   └── test-results-processor.js
β”‚   β”œβ”€β”€ config/                 # Configuration files
β”‚   β”‚   β”œβ”€β”€ webdriver.manager.ts
β”‚   β”‚   └── jest.setup.ts
β”‚   β”œβ”€β”€ data/                   # Test data
β”‚   β”‚   └── test-data.ts
β”‚   └── scripts/                # Utility scripts
β”‚       └── quick-test.ts
β”œβ”€β”€ reports/                    # Generated test reports
β”œβ”€β”€ jest.config.js             # Jest configuration
β”œβ”€β”€ tsconfig.json              # TypeScript configuration
└── package.json               # Dependencies and scripts

οΏ½ Getting Started

Prerequisites

  • Node.js 18.20.5 or higher
  • Chrome Browser version 139.x
  • Git for version control

Installation

  1. Clone the repository

    git clone https://github.com/adityadwic/jest-typescript-web-automation.git
    cd jest-typescript-web-automation
  2. Install dependencies

    npm install
  3. Verify ChromeDriver setup

    npm run chromedriver:version

Quick Start

  1. Run all tests

    npm test
  2. Run specific test scenarios

    npm run test:registration
    npm run test:additional
  3. Generate test reports

    npm run test:report

🎯 Test Scenarios

Main User Registration Flow (18 Steps)

  1. Navigate to automation exercise website
  2. Verify home page visibility
  3. Click Signup/Login button
  4. Verify "New User Signup" text
  5. Enter name and email address
  6. Click Signup button
  7. Verify "ENTER ACCOUNT INFORMATION" text
  8. Fill account details (title, password, date of birth)
  9. Select newsletter checkbox
  10. Select special offers checkbox
  11. Fill address information
  12. Click "Create Account" button
  13. Verify "ACCOUNT CREATED!" message
  14. Click Continue button
  15. Verify user is logged in
  16. Click "Delete Account" button
  17. Verify "ACCOUNT DELETED!" message
  18. Complete cleanup and verification

Additional Test Scenarios

  • Home page elements validation
  • Signup form presence verification
  • Navigation flow testing

πŸ“Š Test Reporting

allure-report-jest

The framework generates multiple types of reports:

1. Custom HTML Dashboard

  • Location: ./reports/test-summary.html
  • Features: Interactive dashboard, step-by-step execution details, success/failure metrics
  • Real-time statistics and execution summary

2. Jest HTML Reports

  • Location: ./reports/html-report/test-report.html
  • Features: Jest native reporting with custom styling

3. JUnit XML Reports

  • Location: ./reports/junit/junit.xml
  • Features: CI/CD integration, pipeline compatibility

4. JSON Reports

  • Location: ./reports/detailed-test-report.json
  • Features: Machine-readable format, custom integrations

πŸ”§ Configuration

Jest Configuration (jest.config.js)

  • Test timeout: 120 seconds
  • TypeScript support with ts-jest
  • Custom reporters configuration
  • Coverage collection settings

WebDriver Configuration

  • Chrome browser optimization for macOS
  • Headless mode support
  • Custom window sizing
  • Security and performance flags

TypeScript Configuration

  • Strict type checking
  • ES2020 target compilation
  • Source map generation
  • Path mapping for clean imports

πŸ“ˆ Performance Metrics

  • Test Execution: ~17-20 seconds for complete flow
  • Step Coverage: 100% execution rate
  • Verification Rate: 51% of steps include assertions
  • Browser Startup: ~2-3 seconds optimized loading

WebDriver Manager

Centralized WebDriver management:

  • Driver initialization
  • Configuration settings
  • Resource cleanup

Test Data Generator

Dynamic test data generation:

  • Random user information
  • Configurable test data
  • Data validation

οΏ½ CI/CD Integration

Ready for integration with:

  • GitHub Actions
  • Jenkins
  • CircleCI
  • Azure DevOps

Example GitHub Actions workflow:

name: Automated Tests
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '18'
      - run: npm install
      - run: npm test

🧩 Extensibility

Adding New Test Cases

  1. Create test file in src/__tests__/
  2. Implement Page Objects in src/pages/
  3. Add test data in src/data/
  4. Configure reporting if needed

Adding New Page Objects

  1. Extend BasePage class
  2. Define locators and methods
  3. Implement page-specific actions
  4. Add proper TypeScript typing

Custom Reporting

  • Extend TestReporter class
  • Add custom logging methods
  • Implement additional report formats
  • Configure output destinations

πŸ“ Scripts Reference

# Test execution
npm test                    # Run all tests
npm run test:registration   # Run main registration flow
npm run test:additional     # Run additional scenarios

# Development
npm run build              # Compile TypeScript
npm run lint               # Run ESLint
npm run format             # Format code with Prettier

# Reporting
npm run test:report        # Generate all reports
npm run test:coverage      # Generate coverage report

πŸ› Troubleshooting

Common Issues

  1. ChromeDriver version mismatch

    npm install chromedriver@latest
  2. Test timeouts

    • Increase timeout in jest.config.js
    • Check network connectivity
    • Verify website availability
  3. Element not found errors

    • Update locators in page objects
    • Add explicit waits
    • Check for page loading issues

πŸ† Best Practices Implemented

  • Page Object Model for maintainable code structure
  • Explicit waits instead of hard-coded delays
  • Independent test cases with proper setup/cleanup
  • Comprehensive error handling and logging
  • Type safety with TypeScript
  • Consistent code style with ESLint/Prettier
  • Detailed reporting for debugging and metrics
  • Modular architecture for easy extension

🀝 Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Automation Exercise for providing the test website
  • Jest community for the excellent testing framework
  • Selenium team for robust browser automation tools

πŸ”— Portfolio Project | ⭐ Give it a star if you found it helpful!

Built with ❀️ by Aditya Dwi Cahyono - Demonstrating modern web automation testing practices

  • Verify page loading completion
  • Check for dynamic content loading
  • Update locators if page structure changed

Debug Mode

Enable verbose logging by setting environment variable:

DEBUG=true npm test

πŸ“ˆ Reporting

  • Console output with step-by-step progress
  • Jest test results
  • Coverage reports in coverage/ directory
  • Test execution logs

πŸ”„ CI/CD Integration

The framework is ready for CI/CD integration with:

  • Headless browser support
  • Exit codes for build status
  • Configurable test environments
  • Report generation

About

This repository demonstrates web automation using Jest for testing and TypeScript for development. It includes test automation scripts for web applications, focusing on testing the functionality and user interactions in the browser.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published