direct.js
3.68 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
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
/*
* This is an implementation of the Direct Driver Provider.
* It is responsible for setting up the account object, tearing
* it down, and setting up the driver correctly.
*/
var fs = require("fs");
var path = require("path");
var q = require("q");
var selenium_webdriver_1 = require("selenium-webdriver");
var chrome_1 = require("selenium-webdriver/chrome");
var firefox_1 = require("selenium-webdriver/firefox");
var exitCodes_1 = require("../exitCodes");
var logger_1 = require("../logger");
var driverProvider_1 = require("./driverProvider");
var SeleniumConfig = require('webdriver-manager/built/lib/config').Config;
var SeleniumChrome = require('webdriver-manager/built/lib/binaries/chrome_driver').ChromeDriver;
var logger = new logger_1.Logger('direct');
var Direct = (function (_super) {
__extends(Direct, _super);
function Direct(config) {
return _super.call(this, config) || this;
}
/**
* Configure and launch (if applicable) the object's environment.
* @public
* @return {q.promise} A promise which will resolve when the environment is
* ready to test.
*/
Direct.prototype.setupEnv = function () {
switch (this.config_.capabilities.browserName) {
case 'chrome':
logger.info('Using ChromeDriver directly...');
break;
case 'firefox':
logger.info('Using FirefoxDriver directly...');
break;
default:
throw new exitCodes_1.BrowserError(logger, 'browserName ' + this.config_.capabilities.browserName +
' is not supported with directConnect.');
}
return q.fcall(function () { });
};
/**
* Create a new driver.
*
* @public
* @override
* @return webdriver instance
*/
Direct.prototype.getNewDriver = function () {
var driver;
switch (this.config_.capabilities.browserName) {
case 'chrome':
var defaultChromeDriverPath = path.resolve(SeleniumConfig.getSeleniumDir(), new SeleniumChrome().executableFilename());
if (process.platform.indexOf('win') === 0) {
defaultChromeDriverPath += '.exe';
}
var chromeDriverFile = this.config_.chromeDriver || defaultChromeDriverPath;
if (!fs.existsSync(chromeDriverFile)) {
throw new exitCodes_1.BrowserError(logger, 'Could not find chromedriver at ' + chromeDriverFile +
'. Run \'webdriver-manager update\' to download binaries.');
}
var service = new chrome_1.ServiceBuilder(chromeDriverFile).build();
driver = new chrome_1.Driver(new selenium_webdriver_1.Capabilities(this.config_.capabilities), service);
break;
case 'firefox':
if (this.config_.firefoxPath) {
this.config_.capabilities['firefox_binary'] = this.config_.firefoxPath;
}
driver = new firefox_1.Driver(this.config_.capabilities);
break;
default:
throw new exitCodes_1.BrowserError(logger, 'browserName ' + this.config_.capabilities.browserName +
' is not supported with directConnect.');
}
this.drivers_.push(driver);
return driver;
};
return Direct;
}(driverProvider_1.DriverProvider));
exports.Direct = Direct;