driverProvider.js
3.03 KB
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
"use strict";
/**
* This is a base driver provider class.
* It is responsible for setting up the account object, tearing
* it down, and setting up the driver correctly.
*/
var q = require("q");
var selenium_webdriver_1 = require("selenium-webdriver");
var DriverProvider = (function () {
function DriverProvider(config) {
this.config_ = config;
this.drivers_ = [];
}
/**
* Get all existing drivers.
*
* @public
* @return array of webdriver instances
*/
DriverProvider.prototype.getExistingDrivers = function () {
return this.drivers_.slice(); // Create a shallow copy
};
/**
* Create a new driver.
*
* @public
* @return webdriver instance
*/
DriverProvider.prototype.getNewDriver = function () {
var builder = new selenium_webdriver_1.Builder()
.usingServer(this.config_.seleniumAddress)
.usingWebDriverProxy(this.config_.webDriverProxy)
.withCapabilities(this.config_.capabilities);
if (this.config_.disableEnvironmentOverrides === true) {
builder.disableEnvironmentOverrides();
}
var newDriver = builder.build();
this.drivers_.push(newDriver);
return newDriver;
};
/**
* Quit a driver.
*
* @public
* @param webdriver instance
*/
DriverProvider.prototype.quitDriver = function (driver) {
var driverIndex = this.drivers_.indexOf(driver);
if (driverIndex >= 0) {
this.drivers_.splice(driverIndex, 1);
}
var deferred = q.defer();
if (driver.getSession() === undefined) {
deferred.resolve();
}
else {
driver.getSession()
.then(function (session_) {
if (session_) {
driver.quit().then(function () {
deferred.resolve();
});
}
else {
deferred.resolve();
}
})
.catch(function (err) {
deferred.resolve();
});
}
return deferred.promise;
};
/**
* Default update job method.
* @return a promise
*/
DriverProvider.prototype.updateJob = function (update) {
return q.fcall(function () { });
};
;
/**
* Default setup environment method.
* @return a promise
*/
DriverProvider.prototype.setupEnv = function () {
return q.fcall(function () { });
};
;
/**
* Teardown and destroy the environment and do any associated cleanup.
* Shuts down the drivers.
*
* @public
* @return {q.promise} A promise which will resolve when the environment
* is down.
*/
DriverProvider.prototype.teardownEnv = function () {
var _this = this;
return q.all(this.drivers_.map(function (driver) {
return _this.quitDriver(driver);
}));
};
return DriverProvider;
}());
exports.DriverProvider = DriverProvider;