forked from webdriverio/webdriverio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
82 lines (71 loc) · 2.61 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
/**
* webdriverio
* https://github.com/Camme/webdriverio
*
* A WebDriver module for nodejs. Either use the super easy help commands or use the base
* Webdriver wire protocol commands. Its totally inspired by jellyfishs webdriver, but the
* goal is to make all the webdriver protocol items available, as near the original as possible.
*
* Copyright (c) 2013 Camilo Tapia <[email protected]>
* Licensed under the MIT license.
*
* Contributors:
* Dan Jenkins <[email protected]>
* Christian Bromann <[email protected]>
* Vincent Voyer <[email protected]>
*/
var createSingleton = require('pragma-singleton'),
WebdriverIO = require('./lib/webdriverio'),
Multibrowser = require('./lib/multibrowser')
ErrorHandler = require('./lib/utils/ErrorHandler'),
package = require('./package.json'),
chainIt = require('chainit'),
PromiseHandler = require('./lib/utils/PromiseHandler');
// expose version number
module.exports.version = package.version;
// expose error handler
module.exports.ErrorHandler = ErrorHandler;
// use the chained API reference to add static methods
var remote = module.exports.remote = function remote(options, Constructor) {
if (typeof options === 'function') {
Constructor = options;
options = {};
} else {
options = options || {};
/**
* allows easy webdriverio-$framework creation (like webdriverio-angular)
*/
Constructor = chainIt(Constructor || WebdriverIO);
/**
* fake promise behavior for all commands
*/
Object.keys(Constructor.prototype).forEach(function(fnName) {
/**
* skip internal commands (e.g. `__addToChain`)
*/
if(fnName.indexOf('__') === 0) {
return;
}
/**
* register Multibrowser so the command gets executed like follows
*
* |--->PromiseHandler
* |--->Multibrowser
* |--->ChainIt
*
* this setup enables calling commands on child processes "synchronously" and having
* all functionality chainIt provides
*/
Constructor.prototype[fnName] = PromiseHandler(fnName, Constructor.prototype[fnName]);
});
}
if (options.singleton) {
var singleton = createSingleton(Constructor);
return new singleton(options);
} else {
return new Constructor(options);
}
};
module.exports.multiremote = function(options) {
return remote(options, Multibrowser);
};