forked from webdriverio/webdriverio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (57 loc) · 2.04 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
/**
* webdriverjs
* https://github.com/Camme/webdriverjs
*
* 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'),
WebdriverJS = require('./lib/webdriverio.js'),
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
module.exports.remote = function remote(options, Constructor) {
if (typeof options === 'function') {
Constructor = options;
options = {};
} else {
options = options || {};
/**
* allows easy webdriverjs-$framework creation (like webdriverjs-angular)
*/
Constructor = chainIt(Constructor || WebdriverJS);
/**
* fake promise behavior for all commands
*/
Object.keys(Constructor.prototype).forEach(function(fnName) {
/**
* skip internal commands (e.g. `__addToChain`)
*/
if(fnName.indexOf('__') === 0) {
return;
}
Constructor.prototype[fnName] = PromiseHandler(fnName, Constructor.prototype[fnName]);
});
}
if (options.singleton) {
var singleton = createSingleton(Constructor);
return new singleton(options);
} else {
return new Constructor(options);
}
};