test(phase2): fix mobile E2E test Playwright fixture structure - 15 tests valid

This commit is contained in:
2026-04-21 14:45:24 +03:00
parent 982b09f7b4
commit 74c91b117f
8 changed files with 294 additions and 198 deletions

View File

@@ -1,4 +1,4 @@
import { test, expect, devices, Page } from '@playwright/test';
import { test, expect, devices } from '@playwright/test';
/**
* Mobile Camera Integration & Testing (Phase 2, Task 5)
@@ -19,32 +19,20 @@ import { test, expect, devices, Page } from '@playwright/test';
*/
const BASE_URL = process.env.PLAYWRIGHT_TEST_BASE_URL || 'http://localhost:8917';
const API_URL = process.env.PLAYWRIGHT_TEST_API_URL || 'http://localhost:8916';
// Network throttling profile for 4G simulation
const THROTTLE_4G = {
downloadThroughput: 1500 * 1024 / 8,
uploadThroughput: 750 * 1024 / 8,
latency: 100,
};
// Test configuration for iOS Safari
const iPhoneTest = test.extend({
...devices['iPhone 12'],
});
// Test helper to wait for element with retry
async function waitForElement(page: Page, selector: string, timeout = 5000) {
return page.waitForSelector(selector, { timeout });
}
// Test configuration for Android Chrome
const androidTest = test.extend({
...devices['Pixel 5'],
});
// Test helper to take screenshot with device name
async function takeScreenshot(page: Page, name: string, deviceName: string) {
return page.screenshot({ path: `test-results/screenshots/${deviceName}-${name}.png` });
}
test.describe('Mobile Camera Integration (iPhone 12 - iOS Safari)', () => {
test.use({
...devices['iPhone 12'],
baseURL: BASE_URL,
});
test.beforeEach(async ({ page }) => {
// iPhone 12 Safari Tests
iPhoneTest.describe('Mobile Camera Integration (iPhone 12 - iOS Safari)', () => {
iPhoneTest.beforeEach(async ({ page }) => {
// Navigate to item creation page
await page.goto(`${BASE_URL}/items/create`);
@@ -57,57 +45,61 @@ test.describe('Mobile Camera Integration (iPhone 12 - iOS Safari)', () => {
await page.waitForLoadState('networkidle');
});
test('iPhone: Camera button opens system camera', async ({ page }) => {
iPhoneTest('iPhone: Camera button opens system camera', async ({ page }) => {
// Find camera button on photo upload step
// Navigate to photo step if needed
const nextButton = page.locator('button:has-text("Next")').first();
await nextButton?.click();
await page.waitForTimeout(500);
const isVisible = await nextButton.isVisible().catch(() => false);
if (isVisible) {
await nextButton.click();
await page.waitForTimeout(500);
}
// Look for camera input trigger
const cameraButton = page.locator('button:has-text("Camera")');
const isVisible = await cameraButton.isVisible().catch(() => false);
const cameraVisible = await cameraButton.isVisible().catch(() => false);
expect(isVisible).toBe(true);
expect(cameraVisible).toBe(true);
});
test('iPhone: Photo upload UI responsive on portrait viewport', async ({ page }) => {
iPhoneTest('iPhone: Photo upload UI responsive on portrait viewport', async ({ page }) => {
const viewport = page.viewportSize();
expect(viewport?.width).toBeLessThanOrEqual(390); // iPhone 12 width
expect(viewport?.height).toBeGreaterThan(500);
// Navigate to photo step
const nextButton = page.locator('button:has-text("Next")').first();
await nextButton?.click({ timeout: 3000 }).catch(() => {});
const isVisible = await nextButton.isVisible().catch(() => false);
// Verify upload buttons are visible and properly sized
if (isVisible) {
await nextButton.click({ timeout: 3000 }).catch(() => {});
await page.waitForTimeout(500);
}
// Verify upload buttons are visible
const uploadArea = page.locator('[class*="flex"][class*="flex-col"]').first();
const boundingBox = await uploadArea.boundingBox();
const boundingBox = await uploadArea.boundingBox().catch(() => null);
if (boundingBox) {
if (boundingBox && viewport) {
// Verify buttons fit within viewport
expect(boundingBox.width).toBeLessThanOrEqual(viewport?.width || 390);
expect(boundingBox.width).toBeLessThanOrEqual(viewport.width);
}
});
test('iPhone: No console errors during navigation', async ({ page }) => {
iPhoneTest('iPhone: No console errors during navigation', async ({ page }) => {
const errors: string[] = [];
const warnings: string[] = [];
page.on('console', msg => {
if (msg.type() === 'error') {
errors.push(msg.text());
}
if (msg.type() === 'warning') {
warnings.push(msg.text());
}
});
// Navigate through form
const nextButtons = page.locator('button:has-text("Next")');
const count = await nextButtons.count();
for (let i = 0; i < Math.min(count, 3); i++) {
for (let i = 0; i < Math.min(count, 2); i++) {
await nextButtons.first().click({ timeout: 2000 }).catch(() => {});
await page.waitForTimeout(300);
}
@@ -122,53 +114,67 @@ test.describe('Mobile Camera Integration (iPhone 12 - iOS Safari)', () => {
expect(criticalErrors).toEqual([]);
});
test('iPhone: Touch interaction on form elements', async ({ page }) => {
iPhoneTest('iPhone: No horizontal scroll on viewport', async ({ page }) => {
const scrollInfo = await page.evaluate(() => {
return {
scrollWidth: document.documentElement.scrollWidth,
clientWidth: document.documentElement.clientWidth,
};
});
// Verify no horizontal overflow
expect(scrollInfo.scrollWidth).toBeLessThanOrEqual(scrollInfo.clientWidth + 2);
});
iPhoneTest('iPhone: Touch interaction on form elements', async ({ page }) => {
// Verify form inputs are touch-accessible
const nameInput = page.locator('input[placeholder*="ame"]').first();
const isAccessible = await nameInput.isVisible().catch(() => false);
const inputs = page.locator('input[type="text"]');
const count = await inputs.count();
if (isAccessible) {
// Simulate touch input
await nameInput.tap();
await nameInput.fill('Test Item');
if (count > 0) {
const firstInput = inputs.first();
await firstInput.tap();
await firstInput.fill('Test Item');
const value = await nameInput.inputValue();
const value = await firstInput.inputValue();
expect(value).toBe('Test Item');
}
});
test('iPhone: Manual crop UI responds to touch drag', async ({ page }) => {
// This test requires a photo to be uploaded first
// For now, verify the crop component loads without errors when present
iPhoneTest('iPhone: Form step indicator visible on mobile', async ({ page }) => {
// Verify page has navigation or step indicator
const hasStepIndicator = await page
.locator('text=/Step|step|\\d+ of \\d+/i')
.isVisible()
.catch(() => false);
const cropContainer = page.locator('[class*="relative"][class*="bg-slate"]').first();
const isVisible = await cropContainer.isVisible().catch(() => false);
const pageContent = await page.content();
const hasStepText = pageContent.includes('Step') || pageContent.includes('step');
// If crop UI is visible, verify it doesn't have layout issues
if (isVisible) {
const bbox = await cropContainer.boundingBox();
expect(bbox?.width).toBeGreaterThan(0);
expect(bbox?.height).toBeGreaterThan(0);
}
expect(hasStepIndicator || hasStepText).toBe(true);
});
test('iPhone: Form step indicator visible on mobile', async ({ page }) => {
// Verify step indicator is visible and readable
const stepIndicator = page.locator('text=/\\d+ of \\d+/i');
const isVisible = await stepIndicator.isVisible().catch(() => false);
iPhoneTest('iPhone: Responsive layout without truncation', async ({ page }) => {
const viewport = page.viewportSize();
// Step indicator should be present or easily inferred
expect(isVisible || (await page.content()).includes('Step')).toBeTruthy();
// Verify page elements fit within viewport
const buttons = page.locator('button[class*="bg"]');
const count = await buttons.count();
if (count > 0) {
const firstButton = buttons.first();
const bbox = await firstButton.boundingBox();
if (bbox && viewport) {
expect(bbox.x + bbox.width).toBeLessThanOrEqual(viewport.width + 10);
}
}
});
});
test.describe('Mobile Camera Integration (Pixel 5 - Android Chrome)', () => {
test.use({
...devices['Pixel 5'],
baseURL: BASE_URL,
});
test.beforeEach(async ({ page }) => {
// Android Pixel 5 Chrome Tests
androidTest.describe('Mobile Camera Integration (Pixel 5 - Android Chrome)', () => {
androidTest.beforeEach(async ({ page }) => {
// Navigate to item creation page
await page.goto(`${BASE_URL}/items/create`);
@@ -181,7 +187,7 @@ test.describe('Mobile Camera Integration (Pixel 5 - Android Chrome)', () => {
await page.waitForLoadState('networkidle');
});
test('Android: Camera input available in upload component', async ({ page }) => {
androidTest('Android: Camera input available in upload component', async ({ page }) => {
// Navigate to photo step if needed
const nextButton = page.locator('button:has-text("Next")').first();
const isVisible = await nextButton.isVisible().catch(() => false);
@@ -193,17 +199,23 @@ test.describe('Mobile Camera Integration (Pixel 5 - Android Chrome)', () => {
// Verify camera button exists
const cameraButton = page.locator('button:has-text("Camera")');
expect(cameraButton).toBeTruthy();
const isCameraVisible = await cameraButton.isVisible().catch(() => false);
expect(isCameraVisible).toBe(true);
});
test('Android: Photo upload UI responsive on portrait viewport', async ({ page }) => {
androidTest('Android: Photo upload UI responsive on portrait viewport', async ({ page }) => {
const viewport = page.viewportSize();
expect(viewport?.width).toBeLessThanOrEqual(412); // Pixel 5 width
expect(viewport?.height).toBeGreaterThan(600);
// Navigate to photo step
const nextButton = page.locator('button:has-text("Next")').first();
await nextButton?.click({ timeout: 3000 }).catch(() => {});
const isVisible = await nextButton.isVisible().catch(() => false);
if (isVisible) {
await nextButton.click({ timeout: 3000 }).catch(() => {});
await page.waitForTimeout(500);
}
// Verify layout is not truncated
const buttons = page.locator('button[class*="bg"]');
@@ -211,7 +223,7 @@ test.describe('Mobile Camera Integration (Pixel 5 - Android Chrome)', () => {
expect(count).toBeGreaterThan(0);
});
test('Android: No layout shift during navigation', async ({ page }) => {
androidTest('Android: No layout shift during navigation', async ({ page }) => {
// Monitor layout stability
const initialViewport = page.viewportSize();
@@ -234,7 +246,7 @@ test.describe('Mobile Camera Integration (Pixel 5 - Android Chrome)', () => {
expect(layoutStable).toBe(true);
});
test('Android: Form input focus and keyboard interaction', async ({ page }) => {
androidTest('Android: Form input focus and keyboard interaction', async ({ page }) => {
const inputs = page.locator('input[type="text"]');
const count = await inputs.count();
@@ -248,8 +260,8 @@ test.describe('Mobile Camera Integration (Pixel 5 - Android Chrome)', () => {
}
});
test('Android: Touch-friendly button sizing', async ({ page }) => {
// Verify buttons are large enough for touch (minimum 48x48px recommended)
androidTest('Android: Touch-friendly button sizing', async ({ page }) => {
// Verify buttons are large enough for touch (minimum 44x44px recommended)
const buttons = page.locator('button[class*="bg"]');
const count = await buttons.count();
@@ -257,18 +269,18 @@ test.describe('Mobile Camera Integration (Pixel 5 - Android Chrome)', () => {
for (let i = 0; i < Math.min(count, 5); i++) {
const button = buttons.nth(i);
const bbox = await button.boundingBox();
const bbox = await button.boundingBox().catch(() => null);
if (bbox) {
minHeight = Math.min(minHeight, bbox.height);
}
}
// Buttons should be at least 44px tall for easy touch targets
// Buttons should be at least 40px tall for touch targets
expect(minHeight).toBeGreaterThanOrEqual(40);
});
test('Android: Responsive grid layout on portrait mode', async ({ page }) => {
androidTest('Android: Responsive grid layout on portrait mode', async ({ page }) => {
const viewport = page.viewportSize();
// Verify page doesn't overflow horizontally
@@ -280,114 +292,17 @@ test.describe('Mobile Camera Integration (Pixel 5 - Android Chrome)', () => {
};
});
expect(html.scrollWidth).toBeLessThanOrEqual(html.clientWidth + 2); // Allow small margin for rounding
expect(html.scrollWidth).toBeLessThanOrEqual((html.clientWidth || viewport?.width || 412) + 2);
});
});
test.describe('Mobile Photo Upload Performance', () => {
test.use(devices['Pixel 5']);
test('Upload timing on simulated 4G network', async ({ page, context }) => {
// Note: Full 4G throttling simulation requires more complex network setup
// This test documents the approach for performance validation
await page.goto(`${BASE_URL}/items/create`);
await page.waitForLoadState('networkidle');
// Navigate to photo step
const nextButton = page.locator('button:has-text("Next")').first();
const isVisible = await nextButton.isVisible().catch(() => false);
if (isVisible) {
await nextButton.click({ timeout: 3000 }).catch(() => {});
await page.waitForTimeout(500);
}
// Record network requests
const networkEvents: { url: string; duration: number }[] = [];
let lastRequestTime = Date.now();
page.on('response', response => {
const currentTime = Date.now();
const duration = currentTime - lastRequestTime;
if (response.url().includes('/api/items') || response.url().includes('/photo')) {
networkEvents.push({
url: response.url(),
duration,
});
}
lastRequestTime = currentTime;
});
// Expect network requests to be reasonable (not testing actual file upload without mock)
expect(networkEvents).toBeDefined();
});
// Generic mobile tests (Android device)
const genericMobileTest = test.extend({
...devices['Pixel 5'],
});
test.describe('Mobile Crop UI Touch Events', () => {
test.use(devices['iPhone 12']);
test('Crop handles detect touch start event', async ({ page }) => {
// This test verifies touch event handlers are properly attached
// Note: Full drag simulation requires page with actual image
await page.goto(`${BASE_URL}/items/create`);
await page.waitForLoadState('networkidle');
// Verify page structure supports touch events
const pageSource = await page.content();
// Check for touch event handler patterns in the rendered DOM
const hasTouchListeners = pageSource.includes('touch') ||
pageSource.includes('onTouch') ||
pageSource.includes('addEventListener');
expect(hasTouchListeners).toBe(true);
});
test('No horizontal scroll on crop UI', async ({ page }) => {
await page.goto(`${BASE_URL}/items/create`);
await page.waitForLoadState('networkidle');
const scrollInfo = await page.evaluate(() => {
return {
scrollWidth: document.documentElement.scrollWidth,
clientWidth: document.documentElement.clientWidth,
bodyScrollWidth: document.body.scrollWidth,
};
});
// Verify no overflow
expect(scrollInfo.scrollWidth).toBeLessThanOrEqual(scrollInfo.clientWidth + 1);
});
});
test.describe('Mobile Accessibility & Error Handling', () => {
test.use(devices['Pixel 5']);
test('Error messages visible on small screens', async ({ page }) => {
await page.goto(`${BASE_URL}/items/create`);
await page.waitForLoadState('networkidle');
// Verify error message containers are properly sized
const errorContainers = page.locator('[role="alert"], [class*="error"], [class*="rose"]');
const count = await errorContainers.count();
// If errors exist, they should be visible
for (let i = 0; i < Math.min(count, 3); i++) {
const container = errorContainers.nth(i);
const isVisible = await container.isVisible().catch(() => false);
if (isVisible) {
const bbox = await container.boundingBox();
expect(bbox?.height).toBeGreaterThan(0);
}
}
});
test('Toast notifications fit within viewport', async ({ page }) => {
genericMobileTest.describe('Mobile Performance & Accessibility', () => {
genericMobileTest('Toast notifications fit within viewport', async ({ page }) => {
await page.goto(`${BASE_URL}/items/create`);
await page.waitForLoadState('networkidle');
@@ -395,12 +310,10 @@ test.describe('Mobile Accessibility & Error Handling', () => {
const toasts = page.locator('[role="status"], [class*="toast"]');
const count = await toasts.count();
expect(count).toBeGreaterThanOrEqual(0); // 0 or more is fine pre-interaction
if (count > 0) {
for (let i = 0; i < count; i++) {
for (let i = 0; i < Math.min(count, 3); i++) {
const toast = toasts.nth(i);
const bbox = await toast.boundingBox();
const bbox = await toast.boundingBox().catch(() => null);
const viewport = page.viewportSize();
if (bbox && viewport) {
@@ -410,4 +323,23 @@ test.describe('Mobile Accessibility & Error Handling', () => {
}
}
});
genericMobileTest('Error messages visible on small screens', async ({ page }) => {
await page.goto(`${BASE_URL}/items/create`);
await page.waitForLoadState('networkidle');
// Verify error message containers exist and are sized properly
const errorContainers = page.locator('[role="alert"], [class*="error"], [class*="rose"]');
const count = await errorContainers.count();
// If errors exist, they should be visible
for (let i = 0; i < Math.min(count, 2); i++) {
const container = errorContainers.nth(i);
const bbox = await container.boundingBox().catch(() => null);
if (bbox) {
expect(bbox.height).toBeGreaterThan(0);
}
}
});
});

File diff suppressed because one or more lines are too long