This repository has been archived by the owner on Mar 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
131 lines (114 loc) · 2.62 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
"use strict";
/**
* Rowdy.
*/
var config = require("./lib/config");
var Server = require("./lib/server");
var clientWrapper = require("./lib/client");
// Stashed, singleton configuration.
var _config;
var rowdy = module.exports = function (cfg) {
_config = config(cfg);
return rowdy;
};
/**
* rowdy.config
*
* Overall configuration object.
*/
Object.defineProperty(rowdy, "config", {
get: function () {
// Lazy initialization.
if (!_config) {
rowdy(require("./config")); // eslint-disable-line global-require
}
return _config;
}
});
/**
* rowdy.config
*
* Configuration with Selenium `desiredCapabilities` and WD `remote`
* initialization options.
*/
Object.defineProperty(rowdy, "setting", {
get: function () {
return rowdy.config.setting;
}
});
/**
* rowdy.setupServer()
*
* Set up new Selenium server and other state.
*
* @param {Function} callback Callback `fn(err, server)` when started
* @returns {void}
*/
rowdy.setupServer = function (callback) {
var server = new Server(rowdy.config);
// Start selenium and wait until ready.
if ((rowdy.setting.server || {}).start) {
return server.start(function (err) {
if (err) { Server.log("[error]".red, err.toString().trim()); }
callback(err, server);
});
}
callback(null, server);
};
/**
* rowdy.setupClient()
*
* Set up a new WD client and other state.
*
* @param {Function} callback Callback `fn(err, client)` when started
* @returns {void}
*/
rowdy.setupClient = function (callback) {
var client = clientWrapper.create(rowdy.config);
client.init(null, function (err) {
if (err) { client.log("[error]".red, err.toString().trim()); }
callback(err, client);
});
};
/**
* rowdy.teardownClient()
*
* Tear down Selenium server and other state.
*
* @param {Object} server Server object
* @param {Function} callback Callback `fn(err)` when stopped
* @returns {void}
*/
rowdy.teardownServer = function (server, callback) {
if ((rowdy.setting.server || {}).start) {
return server.stop(callback);
}
callback();
};
/**
* rowdy.teardownClient()
*
* Tear down WD client and other state.
*
* @param {Object} client Client object
* @param {Function} callback Callback `fn(err)` when stopped
* @returns {void}
*/
rowdy.teardownClient = function (client, callback) {
client.quit(callback);
};
/**
* Adapters.
*/
rowdy.adapters = {
mocha: require("./adapters/mocha") // eslint-disable-line global-require
};
/**
* Helpers.
*/
rowdy.helpers = {
/*eslint-disable global-require*/
js: require("./helpers/js"),
webdriverio: require("./helpers/webdriverio")
/*eslint-enable global-require*/
};