1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | const q = require("q");
|
9 | const selenium_webdriver_1 = require("selenium-webdriver");
|
10 | const bpRunner_1 = require("../bpRunner");
|
11 | class DriverProvider {
|
12 | constructor(config) {
|
13 | this.config_ = config;
|
14 | this.drivers_ = [];
|
15 | this.bpRunner = new bpRunner_1.BlockingProxyRunner(config);
|
16 | }
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | getExistingDrivers() {
|
24 | return this.drivers_.slice();
|
25 | }
|
26 | getBPUrl() {
|
27 | if (this.config_.blockingProxyUrl) {
|
28 | return this.config_.blockingProxyUrl;
|
29 | }
|
30 | return `http://localhost:${this.bpRunner.port}`;
|
31 | }
|
32 | |
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | getNewDriver() {
|
39 | let builder;
|
40 | if (this.config_.useBlockingProxy) {
|
41 | builder =
|
42 | new selenium_webdriver_1.Builder().usingServer(this.getBPUrl()).withCapabilities(this.config_.capabilities);
|
43 | }
|
44 | else {
|
45 | builder = new selenium_webdriver_1.Builder()
|
46 | .usingServer(this.config_.seleniumAddress)
|
47 | .usingWebDriverProxy(this.config_.webDriverProxy)
|
48 | .withCapabilities(this.config_.capabilities);
|
49 | }
|
50 | if (this.config_.disableEnvironmentOverrides === true) {
|
51 | builder.disableEnvironmentOverrides();
|
52 | }
|
53 | let newDriver = builder.build();
|
54 | this.drivers_.push(newDriver);
|
55 | return newDriver;
|
56 | }
|
57 | |
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | quitDriver(driver) {
|
64 | let driverIndex = this.drivers_.indexOf(driver);
|
65 | if (driverIndex >= 0) {
|
66 | this.drivers_.splice(driverIndex, 1);
|
67 | }
|
68 | if (driver.getSession() === undefined) {
|
69 | return selenium_webdriver_1.promise.when(undefined);
|
70 | }
|
71 | else {
|
72 | return driver.getSession()
|
73 | .then((session_) => {
|
74 | if (session_) {
|
75 | return driver.quit();
|
76 | }
|
77 | })
|
78 | .catch(function (err) { });
|
79 | }
|
80 | }
|
81 | |
82 |
|
83 |
|
84 |
|
85 |
|
86 | static quitDrivers(provider, drivers) {
|
87 | let deferred = q.defer();
|
88 | selenium_webdriver_1.promise
|
89 | .all(drivers.map((driver) => {
|
90 | return provider.quitDriver(driver);
|
91 | }))
|
92 | .then(() => {
|
93 | deferred.resolve();
|
94 | }, () => {
|
95 | deferred.resolve();
|
96 | });
|
97 | return deferred.promise;
|
98 | }
|
99 | |
100 |
|
101 |
|
102 |
|
103 | updateJob(update) {
|
104 | return q.fcall(function () { });
|
105 | }
|
106 | ;
|
107 | |
108 |
|
109 |
|
110 | setupEnv() {
|
111 | let driverPromise = this.setupDriverEnv();
|
112 | if (this.config_.useBlockingProxy && !this.config_.blockingProxyUrl) {
|
113 |
|
114 | return driverPromise.then(() => this.bpRunner.start());
|
115 | }
|
116 | return driverPromise;
|
117 | }
|
118 | ;
|
119 | |
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 | teardownEnv() {
|
127 | return DriverProvider.quitDrivers(this, this.drivers_);
|
128 | }
|
129 | }
|
130 | exports.DriverProvider = DriverProvider;
|
131 |
|
\ | No newline at end of file |