-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateReport.ts
More file actions
79 lines (74 loc) · 2.45 KB
/
Copy pathgenerateReport.ts
File metadata and controls
79 lines (74 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const report = require('multiple-cucumber-html-reporter');
import os from 'os';
import { execSync } from 'child_process';
import fs from 'fs';
import path from 'path';
import { version as playwrightVersion } from 'playwright-core/package.json';
// --- Detect environment runtime info ---
const platformName = os.type(); // 'Windows_NT', 'Darwin', 'Linux'
const platformVersion = os.release();
const deviceName = os.hostname();
const nodeVersion = process.version;
// Try to detect active git branch
let gitBranch = 'unknown';
try {
gitBranch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
} catch (e) {
console.warn('⚠️ Git branch not found' + e);
}
// Read the cucumber JSON results
const jsonDir = path.join(__dirname, 'cucumber-report');
const jsonPath = path.join(jsonDir, 'results.json');
let featureCount = 0;
let scenarioCount = 0;
let stepCount = 0;
try {
const data = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
featureCount = data.length;
for (const feature of data) {
scenarioCount += (feature.elements || []).length;
for (const scenario of feature.elements || []) {
stepCount += (scenario.steps || []).length;
}
}
} catch (err) {
console.error('❌ Could not read JSON report:', (err as Error).message);
}
report.generate({
jsonDir: jsonDir,
reportPath: 'cucumber-html-report/',
openReportInBrowser: true,
displayDuration: true,
displayReportTime: true,
pageTitle: 'Playwright BDD Dashboard',
reportName: 'TestRover Playwright BDD Report',
metadata: {
browser: {
name: 'chrome', // Default; Playwright test config usually uses Chrome
version: 'auto-detected at runtime',
},
device: deviceName,
platform: {
name: platformName,
version: platformVersion,
},
},
customData: {
title: 'Playwright Runtime Execution Summary',
data: [
{ label: 'Executed By', value: os.userInfo().username },
{
label: 'Operating System',
value: `${platformName} ${platformVersion}`,
},
{ label: 'Device Hostname', value: deviceName },
{ label: 'Node.js Version', value: nodeVersion },
{ label: 'Playwright Version', value: playwrightVersion },
{ label: 'Git Branch', value: gitBranch },
{ label: 'Features', value: featureCount },
{ label: 'Scenarios', value: scenarioCount },
{ label: 'Steps', value: stepCount },
{ label: 'Report Generated On', value: new Date().toLocaleString() },
],
},
});