forked from rochejul/gulp-angular-protractor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (58 loc) · 2.7 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
/**
* Expose the gulp-angular-protractor plugin
*
* @author Julien Roche
* @version 0.0.1
* @since 0.0.1
*/
'use strict';
var
// Import gulp plugins
gutil = require('gulp-util'),
// Import required API
fs = require('fs'),
path = require('path'),
_ = require('lodash'),
// Import internal API
webDriverFactory = require('./gulp-angular-protractor/web-driver'),
gulpStream = require('./gulp-angular-protractor/gulp-stream'),
defaultOptions = require('./gulp-angular-protractor/default-options.json'),
// Constants
PLUGIN_NAME = require('./gulp-angular-protractor/constants.json').PLUGIN_NAME;
module.exports = function (options) {
gutil.log(PLUGIN_NAME + ' - The plugin is retrieved and will start soon');
let mergedOptions = _.extend({ }, defaultOptions, options);
let webDriver = webDriverFactory(mergedOptions.protractorModulePath);
var
protractorConfiguration,
webDriverShutDownUrl,
webDriverUrl = webDriver.DEFAULT_WEB_DRIVER_URL;
if (!mergedOptions.configFile) {
throw new gutil.PluginError(PLUGIN_NAME, '`configFile` required');
}
if (!fs.existsSync(mergedOptions.configFile)) {
throw new gutil.PluginError(PLUGIN_NAME, 'The protractor configuration file specified by `configFile` does not exist');
}
if (mergedOptions.autoStartStopServer) {
gutil.log(PLUGIN_NAME + ' - We will try to start and stop automatically the WebDriver server');
protractorConfiguration = require(path.resolve(mergedOptions.configFile));
if (!protractorConfiguration || !protractorConfiguration.config) {
throw new gutil.PluginError(PLUGIN_NAME, 'No protractor configuration was exported');
}
if (protractorConfiguration.config.seleniumAddress) {
webDriverShutDownUrl = webDriver.getWebDriverShutdownUrl(protractorConfiguration.config.seleniumAddress);
if (webDriverShutDownUrl) {
webDriverUrl = protractorConfiguration.config.seleniumAddress;
} else {
throw new gutil.PluginError(PLUGIN_NAME, 'The selenium address is not a valid url');
}
}
gutil.log(PLUGIN_NAME + ' - The selenium address is: ' + protractorConfiguration.config.seleniumAddress);
gutil.log(PLUGIN_NAME + ' - The selenium address used is: ' + webDriverUrl);
gutil.log(PLUGIN_NAME + ' - The selenium shutdown address used is: ' + webDriverShutDownUrl);
return gulpStream(mergedOptions, webDriverUrl, true, webDriver);
} else {
gutil.log(PLUGIN_NAME + ' - Basic use (as the gulp-protractor plugin).');
return gulpStream(mergedOptions, webDriverUrl, false, webDriver);
}
};