This document provides comprehensive information about running and writing end-to-end (e2e) tests for the MAIDR project.
- Node.js 22 or higher
- npm (comes with Node.js)
- Git
The following npm scripts are available for running e2e tests:
# Run all e2e tests
npm run e2e
# Run e2e tests with UI mode (for debugging)
npm run e2e:ui
# Run e2e tests in debug mode
npm run e2e:debug
# Install Playwright browsers and dependencies
npm run e2e:installe2e_tests/
├── config/
│ ├── test-config.ts # Playwright configuration
│ └── ... # Additional config files
├── page-objects/
│ ├── base.page.ts # Base page object with common methods
│ └── plots/
│ ├── barplot.page.ts
│ ├── boxplotHorizontal.page.ts
│ ├── boxplotVertical.page.ts
│ ├── scatterplot-page.ts
│ └── ... # Additional plot page objects
├── specs/
│ ├── barplot.spec.ts
│ ├── boxplotHorizontal.spec.ts
│ ├── boxplotVertical.spec.ts
│ ├── scatterplot.spec.ts
│ └── ... # Additional test specs
└── utils/
├── constants.ts # Test constants and selectors
└── ... # Additional utility files
Each plot type's test suite includes the following categories:
- Navigation Controls
- Basic navigation (up, down, left, right)
- First/last element navigation
- Data point navigation
- Box navigation (for boxplots)
- Autoplay Controls
- Forward/backward autoplay
- Upward/downward autoplay (for boxplots)
- Autoplay with timeout configuration
- Mode Controls
- Text mode toggle
- Braille mode toggle
- Sound mode toggle
- Review mode toggle
- Plot-Specific Features
- Axis title verification
- Data point information
- Plot type verification
Each plot type has its own page object class that extends the base page object. Page objects encapsulate:
- Element selectors
- Navigation methods
- Mode control methods
- Plot-specific methods
Example:
class BoxplotVerticalPage extends BasePage {
async moveToDataPointBelow() {
// Implementation
}
async startDownwardAutoplay(options?: { timeout?: number }) {
// Implementation
}
}Tests are organized using Playwright's test framework:
import { expect, test } from '@playwright/test';
import { BoxplotVerticalPage } from '../page-objects/plots/boxplotVertical-page';
test.describe('Boxplot Vertical Tests', () => {
let boxplotVerticalPage: BoxplotVerticalPage;
test.beforeEach(async ({ page }) => {
boxplotVerticalPage = new BoxplotVerticalPage(page);
await boxplotVerticalPage.navigateToPlot('boxplotVertical');
});
test('should move to data point below', async () => {
await boxplotVerticalPage.moveToDataPointBelow();
// Assertions
});
});- Page Object Pattern
- Keep selectors in page objects
- Encapsulate common operations
- Extend base page for shared functionality
- Test Organization
- Group related tests using
test.describe - Use meaningful test descriptions
- Follow the Arrange-Act-Assert pattern
- Error Handling
- Use try-catch blocks for expected errors
- Implement proper error messages
- Handle timeouts appropriately
- Constants
- Use constants for selectors and text
- Keep test data in a separate file
- Use enums for mode states
Run tests in UI mode for visual debugging:
npm run e2e:uiThis opens Playwright's UI where you can:
- View test execution
- Debug step by step
- Inspect elements
- View test traces
For console debugging:
npm run e2e:debug- Timeout Errors
- Increase timeout in test configuration
- Check for slow operations
- Verify element visibility
- Selector Issues
- Use unique, stable selectors
- Wait for elements to be visible
- Check for dynamic content
- State Management
- Reset state between tests
- Handle async operations properly
- Verify mode changes
E2E tests are run:
- On every pull request
- On schedule (every 2 days)
- Can be triggered manually
The workflow includes:
- Node.js setup
- Dependency installation
- Browser installation
- Test execution
- Report generation
When adding new tests:
- Follow the existing structure
- Add appropriate documentation
- Include error handling
- Update this guide if necessary