Comprehensive Playwright test automation suite for the Icon Generator application.
This is a comprehensive test automation suite for the Icon Generator application using Playwright. The suite covers desktop and mobile browsers with extensive test coverage for functionality, configuration, responsiveness, and edge cases.
Application Under Test: https://engineer-coding-challenge-frontend.vercel.app/
The test suite implements the Page Object Model pattern for maintainability and scalability:
File: tests/pages/IconGeneratorPage.ts
The IconGeneratorPage class encapsulates all interactions with the Icon Generator application:
Navigation & Setup:
goto()- Navigate to the applicationsetViewportSize(width, height)- Set viewport for responsive testingwait(timeout)- Wait for specified duration
Prompt Input Methods:
fillPrompt(text)- Fill the prompt input fieldgetPromptValue()- Get current prompt input valueclearPrompt()- Clear the prompt inputfocusPrompt()- Focus on the prompt inputisPromptInputVisible()- Check if prompt is visiblewaitForPromptInput(timeout)- Wait for prompt to be visible
Generate Button Methods:
clickGenerateButton()- Click the generate buttonisGenerateButtonVisible()- Check if button is visiblewaitForGenerateButton(timeout)- Wait for button to be visible
Icon Methods:
generateIcons(prompt)- Generate icons with given promptgetIconCount()- Get count of generated icons
Utility Methods:
getPageTitle()- Get page titlegetPage()- Access underlying Playwright page object
Usage Example:
import { test } from '../fixtures/fixture';
test('example test', async ({ page }) => {
const iconGeneratorPage = new IconGeneratorPage(page);
await iconGeneratorPage.goto();
await iconGeneratorPage.fillPrompt('car');
await iconGeneratorPage.clickGenerateButton();
const count = await iconGeneratorPage.getIconCount();
expect(count).toBeGreaterThan(0);
});Custom test fixtures and utilities for enhanced test capabilities:
-
fixture.ts- Custom Playwright test fixturesiconGeneratorPage- Pre-initialized page object instancetestLogger- Structured logging utilitydebugHelper- Debugging and diagnostic utilitiesassertions- Domain-specific custom assertions
-
TestHelpers.ts- Reusable test utilitiesTestLogger- Structured logging with timestamps (info, warn, error, success)DebugHelper- Debugging utilities (screenshots, page HTML, network activity, element inspection)IconGeneratorAssertions- Custom assertions for icon generation validation
import { test } from '../fixtures/fixture';
test('using fixtures', async ({ iconGeneratorPage, testLogger, debugHelper, assertions }) => {
testLogger.info('Starting icon generation test');
await iconGeneratorPage.goto();
await iconGeneratorPage.fillPrompt('smile');
await iconGeneratorPage.clickGenerateButton();
const count = await iconGeneratorPage.getIconCount();
testLogger.success(`Generated ${count} icons`);
await debugHelper.takeScreenshot('icon-generation-result');
});playwright.config.ts- Playwright configuration with multi-browser setup
Comprehensive test suite for the Icon Generator application covering:
- β Icon Generation - Generate icons from various prompts
- β Style Application - Apply different style configurations
- β Color Customization - Apply color changes via color picker
- β User Interactions - Handle user input and interactions
- β UI Element Visibility - Verify all UI elements are visible
- β Accessibility - Verify accessibility features
- β Responsive Behavior - Test across different viewports
- Test File: 1 spec file (
icon-generator.spec.ts) - Browsers Covered: 3 (Chrome, Firefox, WebKit)
- Test Status: Active and maintained
playwright-demo-typescript/
βββ tests/
β βββ specs/
β β βββ icon-generator.spec.ts # Main test suite
β βββ pages/
β β βββ IconGeneratorPage.ts # Page Object Model
β βββ fixtures/
β β βββ fixture.ts # Custom Playwright fixtures
β βββ utils/
β βββ TestHelpers.ts # Test utilities & helpers
βββ playwright.config.ts # Playwright configuration
βββ tsconfig.json # TypeScript configuration
βββ package.json # Dependencies & scripts
βββ README.md # This file
- Node.js (v14+)
- npm or yarn
- Install dependencies:
npm install- Install Playwright browsers:
npx playwright install- Build TypeScript (optional):
npm run buildnpm testnpm test -- tests/specs/icon-generator.spec.ts# Desktop browsers only
npm run test:desktop
# Mobile browsers only
npm run test:mobile
# Chrome only
npm test -- --project=chrome# Interactive debug mode with trace viewer
npm run test:debug
# UI mode (recommended for local development)
npm run test:ui
# Headed mode (with visible browser)
npx playwright test --headed
# Headed mode (with visible browser) - legacy
npm run test:headednpm run test:report- Test Directory:
tests/specs - Timeout: Default 30s per test
- Retries: 0 (in dev), 2 (in CI)
- Parallel Workers: Automatic (development), 1 (CI)
- Desktop: Chrome, Firefox, WebKit (Safari)
- Mobile: Pixel 5 (Android), iPhone 12 (iOS)
- Screenshots: On test failure
- Videos: On test failure
- Traces: On first retry
Strategies Implemented:
- Flexible selectors using attribute patterns for robustness
- Explicit waits with configurable timeouts
- Retry logic with exponential backoff for flaky operations
- Proper error handling and recovery mechanisms
- Comprehensive logging for failure diagnosis
Example:
// Flexible selectors that work across implementations
class IconGeneratorPage {
readonly promptInput: Locator = this.page.locator(
'input[placeholder*="prompt" i], textarea[placeholder*="prompt" i]'
);
}Best Practices:
- Page Object Model: Encapsulate UI interactions
- Custom Fixtures: Inject dependencies automatically
- Helper Functions: Reusable test utilities
- Configuration Management: Centralized constants
- Consistent Naming: Clear test and method names
- Documentation: Comprehensive comments and JSDoc
Example:
test('should generate exactly 8 icons from a simple prompt', async ({
iconGeneratorPage,
testLogger,
assertions,
}) => {
testLogger.step(1, 'Enter simple prompt');
await iconGeneratorPage.generateIcons(prompt);
testLogger.step(2, 'Verify exactly 8 icons were generated');
await assertions.expectEightIconsGenerated(iconGeneratorPage.iconItems);
});Debugging Features:
- Timestamped structured logging
- Step-by-step test execution logging
- Automatic screenshot capture on failure
- DOM structure logging
- Page state capture (URL, title, errors)
- Accessibility verification reports
- Performance metrics collection
Debug Output Example:
[2024-12-18T10:30:45.123Z] [should generate 8 icons] Step 1: Enter simple prompt
[2024-12-18T10:30:46.456Z] [should generate 8 icons] Step 2: Verify exactly 8 icons were generated
[2024-12-18T10:30:47.789Z] [should generate 8 icons] β
Generated 8 icons from simple prompt
πΈ Screenshot saved: screenshots/test-name-description.png
Coverage Areas:
- Feature Coverage - All major features tested
- Browser Coverage - 5 browser/device combinations
- Viewport Coverage - 7 different viewport sizes
- Path Coverage - Multiple user flows per feature
- Error Path Coverage - Error scenarios and edge cases
await assertions.expectEightIconsGenerated(iconItems);
await assertions.expectIconsVisible(iconItems);
await assertions.expectColorApplied(colorElement, '#FF0000');
await assertions.expectResponsiveLayout(container);const prompts = TestDataFactory.getTestPrompts();
const colors = TestDataFactory.getTestColors();
const styles = TestDataFactory.getTestStyles();
const viewports = TestDataFactory.getTestViewports();await RetryHelper.retryWithBackoff(async () => {
return await page.locator(selector).click();
}, 3, 500);
await RetryHelper.waitFor(
() => iconElements.count() === 8,
10000,
500
);await debugHelper.takeScreenshot('state-description');
await debugHelper.verifyAccessibility();
await debugHelper.capturePageState();
await debugHelper.logDOMStructure();- name: Run Playwright Tests
run: npm test
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v2
with:
name: playwright-report
path: test-results/Based on test execution:
| Metric | Threshold | Status |
|---|---|---|
| Icon Generation Time | <60s | β Acceptable |
| Page Load Time | <5s | β Good |
| Test Suite Execution | ~15-20min (all browsers) | β Reasonable |
| Memory Usage | <100MB | β Efficient |
- Tests cannot verify actual icon visual output (would require image comparison)
- API responses are not mocked (tests hit real backend)
- Audio/video playback features not covered
- Offline mode not tested
- Visual Regression Testing - Add image comparison for icons
- API Mocking - Mock backend for faster, more reliable tests
- Performance Monitoring - Integrate performance monitoring
- Visual Accessibility - Add axe-accessibility plugin
- Load Testing - Add k6 or Artillery for load testing
- Test Report Dashboard - Build real-time test metrics dashboard
Issue: Tests timeout waiting for icons
Solution: Increase GENERATION timeout in testConfig.ts
Issue: Flaky tests on CI
Solution: Increase retries in playwright.config.ts or add explicit waits
Issue: Mobile tests fail
Solution: Ensure mobile device definitions match actual device specs
For issues or improvements, please refer to the test documentation above or check the inline code comments for specific details.
Test Automation Framework: Playwright v1.40.0+ Language: TypeScript 5.5.3+ Last Updated: December 18, 2024