chore: clean up mobile test files and update components

This commit is contained in:
张翔
2026-03-05 14:23:19 +08:00
parent 0bb1f5c12a
commit 060566fd73
13 changed files with 9 additions and 3838 deletions
-138
View File
@@ -450,142 +450,4 @@ export class BasePage {
});
});
}
async tapElement(selector: string): Promise<void> {
const element = this.page.locator(selector);
const box = await element.boundingBox();
if (box) {
const x = box.x + box.width / 2;
const y = box.y + box.height / 2;
await this.page.touchscreen.tap(x, y);
} else {
await element.click();
}
}
async swipe(start: { x: number; y: number }, end: { x: number; y: number }): Promise<void> {
await this.page.touchscreen.tap(start.x, start.y);
await this.page.touchscreen.touchMove(end.x, end.y);
await this.page.touchscreen.touchEnd();
}
async longPress(selector: string, duration: number = 1000): Promise<void> {
const element = this.page.locator(selector);
const box = await element.boundingBox();
if (box) {
const x = box.x + box.width / 2;
const y = box.y + box.height / 2;
await this.page.touchscreen.tap(x, y);
await this.page.waitForTimeout(duration);
} else {
await element.click();
}
}
async pinchZoom(selector: string, scale: number = 1.5): Promise<void> {
const element = this.page.locator(selector);
const box = await element.boundingBox();
if (box) {
const centerX = box.x + box.width / 2;
const centerY = box.y + box.height / 2;
const finger1 = { x: centerX - 50, y: centerY };
const finger2 = { x: centerX + 50, y: centerY };
await this.page.touchscreen.tap(finger1.x, finger1.y);
await this.page.touchscreen.tap(finger2.x, finger2.y);
const newFinger1 = { x: centerX - 50 / scale, y: centerY };
const newFinger2 = { x: centerX + 50 / scale, y: centerY };
await this.page.touchscreen.touchMove(newFinger1.x, newFinger1.y);
await this.page.touchscreen.touchMove(newFinger2.x, newFinger2.y);
await this.page.touchscreen.touchEnd();
await this.page.touchscreen.touchEnd();
}
}
async waitForMobileLoad(): Promise<void> {
await this.page.waitForLoadState('domcontentloaded');
await this.page.waitForTimeout(500);
}
async checkTouchTarget(selector: string): Promise<boolean> {
const element = this.page.locator(selector);
const box = await element.boundingBox();
if (box) {
return box.width >= 44 && box.height >= 44;
}
return false;
}
async captureMobileScreenshot(name: string): Promise<void> {
const screenshotDir = 'test-results/mobile-screenshots';
if (!fs.existsSync(screenshotDir)) {
fs.mkdirSync(screenshotDir, { recursive: true });
}
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
const filename = `${timestamp}-${name}.png`;
await this.page.screenshot({
path: path.join(screenshotDir, filename),
fullPage: true
});
}
async measureLCP(): Promise<number> {
const vitals = await this.getCoreWebVitals();
return vitals.largestContentfulPaint;
}
async measureFID(): Promise<number> {
const vitals = await this.getCoreWebVitals();
return vitals.firstInputDelay;
}
async measureCLS(): Promise<number> {
const vitals = await this.getCoreWebVitals();
return vitals.cumulativeLayoutShift;
}
async measureTTI(): Promise<number> {
const metrics = await this.measurePerformance();
return metrics.domContentLoaded;
}
async measureTTFB(): Promise<number> {
const timing = await this.page.evaluate(() => {
return performance.timing;
});
return timing.responseStart - timing.navigationStart;
}
async handleError(error: Error, context: string): Promise<void> {
const errorInfo = {
timestamp: new Date().toISOString(),
context,
message: error.message,
stack: error.stack,
url: this.page.url(),
};
await this.log(`Error in ${context}: ${error.message}`, 'error');
await this.captureMobileScreenshot(`error-${context}`);
}
async logAction(action: string, details: any): Promise<void> {
const logInfo = {
timestamp: new Date().toISOString(),
action,
details,
url: this.page.url(),
};
await this.log(`Action: ${action}`, 'info');
}
}