A comprehensive, enterprise-grade TypeScript-based Selenium automation testing framework implementing industry best practices for scalable and maintainable test automation.
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
- 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
| 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 |
- 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
before(): Browser setup and configurationbeforeEach(): Navigate to test pages and prepare test dataafterEach(): Clean up cookies and session dataafter(): Browser teardown and resource cleanup
- 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
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
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 |
- Node.js (v14+ recommended)
- npm or yarn package manager
- Chrome Browser (or other supported browsers)
- Git for version control
-
Clone the repository:
git clone <repository-url> cd selenium-test-project
-
Install dependencies:
npm install
-
Verify installation:
npm run --version npx tsc --version
npm test# 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# Chrome (default)
BROWSER=chrome npm test
# Firefox
BROWSER=firefox npm test
# Safari
BROWSER=safari npm testHEADLESS=true npm test- π 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)
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 stored in page objects
- Environment-specific configurations supported
- Sensitive data can be stored in environment variables
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
Logger.info('Test step completed');
Logger.warn('Element not found, retrying...');
Logger.error('Test failed with exception');
Logger.debug('Variable value: ' + value);- Console output with colored formatting
- Detailed error messages with stack traces
- Test execution time tracking
- Browser console error capture
// 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);
}
}// 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!');
});
});
});We welcome contributions! Please follow these guidelines:
- Fork the repository
- Create a feature branch:
git checkout -b feature/new-test-case - Make your changes following TypeScript and testing best practices
- Add tests for new functionality
- Run the test suite:
npm test - Commit your changes:
git commit -m "Add new test case for XYZ" - Push to the branch:
git push origin feature/new-test-case - Create a Pull Request
- 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
- Create page object in
src/pages/ - Create test file in
src/tests/ - Follow existing naming conventions
- Include 5-second static waits for manual verification
- Add comprehensive assertions
- 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
- Selenium WebDriver - Browser automation
- Mocha - Test framework and runner
- Chai - Assertion library
- TypeScript - Language documentation
This project is licensed under the ISC License. See the LICENSE file for more details.
If you encounter any issues or have questions:
- Check the existing issues in the repository
- Create a new issue with detailed description
- Include error logs and environment information
- Tag the issue with appropriate labels
Happy Testing! π
Built with β€οΈ using TypeScript, Selenium WebDriver, Mocha, and Chai
