-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.js
75 lines (57 loc) · 1.65 KB
/
runner.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
var webdriver = require('./lib/webdriver/webdriver-extended')
, properties = require('./config/properties.json')
, extend = require("./lib/utils/extend").extend;
function Runner(opts, tests){
if(!(this instanceof Runner)){
return new Runner(opts, tests);
}
opts = extend(properties, opts);
this.server = null;
this.driver = null;
this._startSeleniumServer(opts);
this._buildDriver(opts);
var page = require("./lib/client/factory").factory.setDriver(this.driver).setConfig(opts).getInstance();
if(opts.screenshotFailedTest){
page.includeScreenshotOnTestFailed();
}
this.loadTests(tests);
return this;
}
Runner.prototype._startSeleniumServer = function(opts){
var Server;
if(opts.browser === "phantomjs"){
Server = require("./lib/selenium/phantomServer");
}
else{
Server = require("./lib/selenium/server");
}
this.server = new Server(opts);
this.server.start();
return this;
};
Runner.prototype._buildDriver = function(opts){
var capabilities = webdriver.Capabilities[opts.browser]();
this.driver = new webdriver.Builder().
usingServer(this.server.address()).
withCapabilities(capabilities).
build();
this.driver.manage().window().maximize();
};
Runner.prototype.loadTests = function(tests){
if(!tests || tests.length === 0){
return;
}
if(Array.isArray(tests)){
tests.map(function(test){
return require(test);
});
}
else{
require(tests);
}
return this;
};
Runner.setConfig = function(conf){
return Runner(conf);
};
module.exports = Runner;