forked from john-doherty/selenium-cucumber-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·145 lines (112 loc) · 4.76 KB
/
index.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
'use strict';
var fs = require('fs-plus');
var path = require('path');
var program = require('commander');
var pjson = require('./package.json');
var cucumber = require('cucumber');
function collectPaths(value, paths) {
paths.push(value);
return paths;
}
function coerceInt(value, defaultValue) {
var int = parseInt(value);
if (typeof int === 'number') return int;
return defaultValue;
}
var config = {
steps: './step-definitions',
pageObjects: './page-objects',
sharedObjects: './shared-objects',
reports: './reports',
browser: 'chrome',
timeout: 15000
};
var configFileName = path.resolve(process.cwd(), 'selenium-cucumber-js.json');
if (fs.isFileSync(configFileName)) {
config = Object.assign(config, require(configFileName));
}
program
.version(pjson.version)
.description(pjson.description)
.option('-s, --steps <path>', 'path to step definitions. defaults to ' + config.steps, config.steps)
.option('-p, --pageObjects <path>', 'path to page objects. defaults to ' + config.pageObjects, config.pageObjects)
.option('-o, --sharedObjects [paths]', 'path to shared objects (repeatable). defaults to ' + config.sharedObjects, collectPaths, [config.sharedObjects])
.option('-b, --browser <path>', 'name of browser to use. defaults to ' + config.browser, config.browser)
.option('-r, --reports <path>', 'output path to save reports. defaults to ' + config.reports, config.reports)
.option('-d, --disableLaunchReport [optional]', 'Disables the auto opening the browser with test report')
.option('-j, --junit <path>', 'output path to save junit-report.xml defaults to ' + config.reports)
.option('-t, --tags <tagName>', 'name of tag to run', collectPaths, [])
.option('-f, --featureFile <path>', 'a specific feature file to run')
.option('-x, --timeOut <n>', 'steps definition timeout in milliseconds. defaults to ' + config.timeout, coerceInt, config.timeout)
.option('-n, --noScreenshot [optional]', 'disable auto capturing of screenshots when an error is encountered')
.parse(process.argv);
program.on('--help', function () {
console.log(' For more details please visit https://github.com/john-doherty/selenium-cucumber-js#readme\n');
});
// store browserName globally (used within world.js to build driver)
global.browserName = program.browser;
// store Eyes Api globally (used within world.js to set Eyes)
global.eyesKey = config.eye_key
// used within world.js to import page objects
global.pageObjectPath = path.resolve(program.pageObjects);
// used within world.js to output reports
global.reportsPath = path.resolve(program.reports);
if (!fs.existsSync(program.reports)) {
fs.makeTreeSync(program.reports);
}
// used within world.js to decide if reports should be generated
global.disableLaunchReport = (program.disableLaunchReport);
// used with world.js to determine if a screenshot should be captured on error
global.noScreenshot = (program.noScreenshot);
// used within world.js to output junit reports
global.junitPath = path.resolve(program.junit || program.reports);
// set the default timeout to 10 seconds if not already globally defined or passed via the command line
global.DEFAULT_TIMEOUT = global.DEFAULT_TIMEOUT || program.timeOut || 10 * 1000;
// used within world.js to import shared objects into the shared namespace
global.sharedObjectPaths = program.sharedObjects.map(function (item) {
return path.resolve(item);
});
// rewrite command line switches for cucumber
process.argv.splice(2, 100);
// allow a specific feature file to be executed
if (program.featureFile) {
process.argv.push(program.featureFile);
}
// add switch to tell cucumber to produce json report files
process.argv.push('-f');
process.argv.push('pretty');
process.argv.push('-f');
process.argv.push('json:' + path.resolve(__dirname, global.reportsPath, 'cucumber-report.json'));
// add cucumber world as first required script (this sets up the globals)
process.argv.push('-r');
process.argv.push(path.resolve(__dirname, 'runtime/world.js'));
// add path to import step definitions
process.argv.push('-r');
process.argv.push(path.resolve(program.steps));
// add tag
if (program.tags) {
program.tags.forEach(function (tag) {
process.argv.push('-t');
process.argv.push(tag);
})
}
// add strict option (fail if there are any undefined or pending steps)
process.argv.push('-S');
//
// execute cucumber
//
var cucumberCli = cucumber.Cli(process.argv);
global.cucumber = cucumber;
cucumberCli.run(function (succeeded) {
var code = succeeded ? 0 : 1;
function exitNow() {
process.exit(code);
}
if (process.stdout.write('')) {
exitNow();
}
else {
// write() returned false, kernel buffer is not empty yet...
process.stdout.on('drain', exitNow);
}
});