|
| 1 | +# Mobile Device Emulation & Testing Design |
| 2 | + |
| 3 | +**Date:** 2025-12-23 |
| 4 | +**Status:** Approved |
| 5 | +**Author:** Claude + Keven |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +Add automated E2E testing across mobile and tablet devices using Playwright's built-in device emulation. |
| 10 | + |
| 11 | +## Requirements |
| 12 | + |
| 13 | +- Run all existing E2E tests on multiple device configurations |
| 14 | +- Support iOS, Android, and Tablet viewports |
| 15 | +- Include Edge browser for desktop coverage |
| 16 | +- Sequential execution to minimize CI resource usage |
| 17 | + |
| 18 | +## Device Configuration |
| 19 | + |
| 20 | +| Device | Browser | Type | |
| 21 | +| -------------- | ------- | ---------------- | |
| 22 | +| Desktop Chrome | Chrome | Desktop | |
| 23 | +| Desktop Edge | Edge | Desktop | |
| 24 | +| iPhone 14 | Safari | Mobile (iOS) | |
| 25 | +| Pixel 7 | Chrome | Mobile (Android) | |
| 26 | +| iPad (gen 7) | Safari | Tablet | |
| 27 | + |
| 28 | +## Implementation |
| 29 | + |
| 30 | +### playwright.config.ts |
| 31 | + |
| 32 | +```typescript |
| 33 | +import { defineConfig, devices } from '@playwright/test' |
| 34 | + |
| 35 | +export default defineConfig({ |
| 36 | + testDir: './tests/e2e', |
| 37 | + fullyParallel: false, |
| 38 | + workers: 1, |
| 39 | + forbidOnly: !!process.env.CI, |
| 40 | + retries: process.env.CI ? 2 : 0, |
| 41 | + reporter: [['html', { open: 'never' }], ['list']], |
| 42 | + use: { |
| 43 | + baseURL: 'http://localhost:5173', |
| 44 | + trace: 'on-first-retry', |
| 45 | + screenshot: 'only-on-failure', |
| 46 | + video: 'retain-on-failure', |
| 47 | + }, |
| 48 | + projects: [ |
| 49 | + { |
| 50 | + name: 'Desktop Chrome', |
| 51 | + use: { ...devices['Desktop Chrome'] }, |
| 52 | + }, |
| 53 | + { |
| 54 | + name: 'Desktop Edge', |
| 55 | + use: { ...devices['Desktop Edge'] }, |
| 56 | + }, |
| 57 | + { |
| 58 | + name: 'iPhone 14', |
| 59 | + use: { ...devices['iPhone 14'] }, |
| 60 | + }, |
| 61 | + { |
| 62 | + name: 'Pixel 7', |
| 63 | + use: { ...devices['Pixel 7'] }, |
| 64 | + }, |
| 65 | + { |
| 66 | + name: 'iPad', |
| 67 | + use: { ...devices['iPad (gen 7)'] }, |
| 68 | + }, |
| 69 | + ], |
| 70 | + webServer: { |
| 71 | + command: 'pnpm dev', |
| 72 | + url: 'http://localhost:5173', |
| 73 | + reuseExistingServer: !process.env.CI, |
| 74 | + }, |
| 75 | +}) |
| 76 | +``` |
| 77 | + |
| 78 | +### package.json Scripts |
| 79 | + |
| 80 | +```json |
| 81 | +{ |
| 82 | + "test:e2e": "playwright test", |
| 83 | + "test:e2e:desktop": "playwright test --project='Desktop Chrome' --project='Desktop Edge'", |
| 84 | + "test:e2e:mobile": "playwright test --project='iPhone 14' --project='Pixel 7' --project='iPad'", |
| 85 | + "test:e2e:ios": "playwright test --project='iPhone 14' --project='iPad'", |
| 86 | + "test:e2e:android": "playwright test --project='Pixel 7'", |
| 87 | + "test:e2e:device": "playwright test --project" |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +### Usage |
| 92 | + |
| 93 | +```bash |
| 94 | +# Run all devices sequentially |
| 95 | +pnpm test:e2e |
| 96 | + |
| 97 | +# Desktop browsers only (quick check) |
| 98 | +pnpm test:e2e:desktop |
| 99 | + |
| 100 | +# Mobile/tablet devices only |
| 101 | +pnpm test:e2e:mobile |
| 102 | + |
| 103 | +# iOS devices only |
| 104 | +pnpm test:e2e:ios |
| 105 | + |
| 106 | +# Android only |
| 107 | +pnpm test:e2e:android |
| 108 | + |
| 109 | +# Single device for debugging |
| 110 | +pnpm test:e2e:device "iPhone 14" |
| 111 | +``` |
| 112 | + |
| 113 | +## Execution Order |
| 114 | + |
| 115 | +1. Desktop Chrome |
| 116 | +2. Desktop Edge |
| 117 | +3. iPhone 14 |
| 118 | +4. Pixel 7 |
| 119 | +5. iPad |
| 120 | + |
| 121 | +## Reporting |
| 122 | + |
| 123 | +- **HTML Report:** Results grouped by device with filtering |
| 124 | +- **Screenshots:** Captured at device resolution on failure |
| 125 | +- **Video:** Retained on failure for debugging mobile issues |
| 126 | +- **Console:** List reporter shows `[Device Name] › test-name` |
| 127 | + |
| 128 | +## Estimated Timing |
| 129 | + |
| 130 | +- Each device configuration: ~3-4 minutes |
| 131 | +- Total sequential run (5 devices): ~15-20 minutes |
| 132 | + |
| 133 | +## Test Considerations |
| 134 | + |
| 135 | +Playwright automatically handles: |
| 136 | + |
| 137 | +- Touch event simulation for mobile |
| 138 | +- Correct viewport and device scale factor |
| 139 | +- Mobile user agent strings |
| 140 | +- Responsive CSS breakpoint rendering |
| 141 | + |
| 142 | +Potential manual adjustments (if needed): |
| 143 | + |
| 144 | +- Mobile hamburger menu navigation |
| 145 | +- Hover-state alternatives for touch devices |
| 146 | + |
| 147 | +## Files Modified |
| 148 | + |
| 149 | +1. `playwright.config.ts` - Device projects and settings |
| 150 | +2. `package.json` - New test scripts |
0 commit comments