feat: implement HTML report generation in MobileTestReporter
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import { MobileTestReporter } from '../../utils/MobileTestReporter';
|
||||||
|
|
||||||
|
test('MobileTestReporter should generate HTML report', async () => {
|
||||||
|
const reporter = new MobileTestReporter({} as any);
|
||||||
|
const html = reporter.generateHtmlReport({
|
||||||
|
suites: [],
|
||||||
|
duration: 10000,
|
||||||
|
status: 'passed',
|
||||||
|
} as any);
|
||||||
|
|
||||||
|
expect(html).toContain('移动端测试报告');
|
||||||
|
expect(html).toContain('总测试数');
|
||||||
|
expect(html).toContain('通过');
|
||||||
|
expect(html).toContain('失败');
|
||||||
|
});
|
||||||
@@ -45,4 +45,54 @@ export class MobileTestReporter {
|
|||||||
duration: results.duration,
|
duration: results.duration,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generateHtmlReport(results: FullResult): string {
|
||||||
|
const overview = this.generateOverview(results);
|
||||||
|
|
||||||
|
return `
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>移动端测试报告</title>
|
||||||
|
<style>
|
||||||
|
body { font-family: Arial, sans-serif; margin: 20px; }
|
||||||
|
.overview { background: #f5f5f5; padding: 20px; border-radius: 8px; margin-bottom: 20px; }
|
||||||
|
.stat { display: inline-block; margin: 0 20px 10px 0; }
|
||||||
|
.stat-value { font-size: 24px; font-weight: bold; }
|
||||||
|
.stat-label { color: #666; }
|
||||||
|
.passed { color: #4caf50; }
|
||||||
|
.failed { color: #f44336; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>移动端测试报告</h1>
|
||||||
|
<div class="overview">
|
||||||
|
<div class="stat">
|
||||||
|
<div class="stat-value">${overview.total}</div>
|
||||||
|
<div class="stat-label">总测试数</div>
|
||||||
|
</div>
|
||||||
|
<div class="stat">
|
||||||
|
<div class="stat-value passed">${overview.passed}</div>
|
||||||
|
<div class="stat-label">通过</div>
|
||||||
|
</div>
|
||||||
|
<div class="stat">
|
||||||
|
<div class="stat-value failed">${overview.failed}</div>
|
||||||
|
<div class="stat-label">失败</div>
|
||||||
|
</div>
|
||||||
|
<div class="stat">
|
||||||
|
<div class="stat-value">${(overview.duration / 1000).toFixed(2)}s</div>
|
||||||
|
<div class="stat-label">执行时间</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async saveReport(report: string, outputPath: string): Promise<void> {
|
||||||
|
const fs = await import('fs/promises');
|
||||||
|
await fs.writeFile(outputPath, report, 'utf-8');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user