forked from webdriverio-community/wdio-video-reporter
-
Notifications
You must be signed in to change notification settings - Fork 5
/
cucumber.js
118 lines (97 loc) · 2.87 KB
/
cucumber.js
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import allureReporter from '@wdio/allure-reporter';
import mkdirp from 'mkdirp';
import fs from 'fs-extra';
import path from 'path';
import helpers from '../helpers.js';
import config from '../config.js';
import notAvailableImage from '../assets/not-available.png';
export default {
/**
* Init
*/
frameworkInit () {
},
/**
* Set reporter options
*/
constructor () {
},
/**
* Set wdio config options
*/
onRunnerStart () {
},
/**
* Save screenshot or add not available image movie stills
*/
onAfterCommand () {
},
/**
* Add suite name to naming structure
*/
onSuiteStart (suite) {
this.testnameStructure.push(suite.title.replace(/ /g, '-').replace(/-{2,}/g, '-'));
if (suite.type === 'scenario') {
const fullname = this.testnameStructure.slice(1).reduce((cur, acc) => cur + '--' + acc, this.testnameStructure[0]);
let browserName = browser.capabilities.browserName.toUpperCase();
if (browser.capabilities.deviceType) {
browserName += `-${browser.capabilities.deviceType.replace(/ /g, '-')}`;
}
this.testname = helpers.generateFilename(browserName, fullname);
this.frameNr = 0;
this.recordingPath = path.resolve(config.outputDir, config.rawPath, this.testname);
if (!fs.existsSync(this.recordingPath)) {
mkdirp.sync(this.recordingPath);
}
}
},
/**
* Clear suite name from naming structure
*/
onSuiteEnd (suite) {
if (config.usingAllure) {
if (browser.capabilities.deviceType) {
allureReporter.addArgument('deviceType', browser.capabilities.deviceType);
}
if (browser.capabilities.browserVersion) {
allureReporter.addArgument('browserVersion', browser.capabilities.browserVersion);
}
}
if (suite.type === 'scenario') {
const hasFailedTests = suite.tests.filter(test => test.state === 'failed').length > 0;
const allTestsPassed = suite.tests.filter(test => test.state === 'failed').length === 0;
if (hasFailedTests || (allTestsPassed && config.saveAllVideos)) {
const filePath = path.resolve(this.recordingPath, this.frameNr.toString().padStart(4, '0') + '.png');
try {
browser.saveScreenshot(filePath);
helpers.debugLog('- Screenshot!!\n');
} catch (e) {
fs.writeFile(filePath, notAvailableImage, 'base64');
helpers.debugLog('- Screenshot not available...\n');
}
helpers.generateVideo.call(this);
}
}
},
/**
* Setup filename based on test name and prepare storage directory
*/
onTestStart () {
},
/**
* Remove empty directories
*/
onTestSkip () {
},
/**
* Add attachment to Allue if applicable and start to generate the video
* Not applicable to Cucumber
*/
onTestEnd () {
},
/**
* Finalize report if using allure and clean up
*/
onRunnerEnd () {
},
};