1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | const fs = require("fs");
|
9 | const path = require("path");
|
10 | const q = require("q");
|
11 | const selenium_webdriver_1 = require("selenium-webdriver");
|
12 | const chrome_1 = require("selenium-webdriver/chrome");
|
13 | const exitCodes_1 = require("../exitCodes");
|
14 | const logger_1 = require("../logger");
|
15 | const driverProvider_1 = require("./driverProvider");
|
16 | const SeleniumConfig = require('webdriver-manager/built/lib/config').Config;
|
17 | let logger = new logger_1.Logger('direct');
|
18 | class Direct extends driverProvider_1.DriverProvider {
|
19 | constructor(config) {
|
20 | super(config);
|
21 | }
|
22 | |
23 |
|
24 |
|
25 |
|
26 |
|
27 | setupDriverEnv() {
|
28 | switch (this.config_.capabilities.browserName) {
|
29 | case 'chrome':
|
30 | logger.info('Using ChromeDriver directly...');
|
31 | break;
|
32 | case 'firefox':
|
33 | logger.info('Using FirefoxDriver directly...');
|
34 | break;
|
35 | default:
|
36 | throw new exitCodes_1.BrowserError(logger, 'browserName ' + this.config_.capabilities.browserName +
|
37 | ' is not supported with directConnect.');
|
38 | }
|
39 | return q.fcall(function () { });
|
40 | }
|
41 | |
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | getNewDriver() {
|
49 | let driver;
|
50 | switch (this.config_.capabilities.browserName) {
|
51 | case 'chrome':
|
52 | let chromeDriverFile;
|
53 | if (this.config_.chromeDriver) {
|
54 | chromeDriverFile = this.config_.chromeDriver;
|
55 | }
|
56 | else {
|
57 | try {
|
58 | let updateJson = path.resolve(SeleniumConfig.getSeleniumDir(), 'update-config.json');
|
59 | let updateConfig = JSON.parse(fs.readFileSync(updateJson).toString());
|
60 | chromeDriverFile = updateConfig.chrome.last;
|
61 | }
|
62 | catch (e) {
|
63 | throw new exitCodes_1.BrowserError(logger, 'Could not find update-config.json. ' +
|
64 | 'Run \'webdriver-manager update\' to download binaries.');
|
65 | }
|
66 | }
|
67 | if (!fs.existsSync(chromeDriverFile)) {
|
68 | throw new exitCodes_1.BrowserError(logger, 'Could not find chromedriver at ' + chromeDriverFile +
|
69 | '. Run \'webdriver-manager update\' to download binaries.');
|
70 | }
|
71 | let chromeService = new chrome_1.ServiceBuilder(chromeDriverFile).build();
|
72 |
|
73 |
|
74 |
|
75 | driver =
|
76 | require('selenium-webdriver/chrome')
|
77 | .Driver.createSession(new selenium_webdriver_1.Capabilities(this.config_.capabilities), chromeService);
|
78 | break;
|
79 | case 'firefox':
|
80 | let geckoDriverFile;
|
81 | try {
|
82 | let updateJson = path.resolve(SeleniumConfig.getSeleniumDir(), 'update-config.json');
|
83 | let updateConfig = JSON.parse(fs.readFileSync(updateJson).toString());
|
84 | geckoDriverFile = updateConfig.gecko.last;
|
85 | }
|
86 | catch (e) {
|
87 | throw new exitCodes_1.BrowserError(logger, 'Could not find update-config.json. ' +
|
88 | 'Run \'webdriver-manager update\' to download binaries.');
|
89 | }
|
90 |
|
91 | const FirefoxServiceBuilder = require('selenium-webdriver/firefox').ServiceBuilder;
|
92 | let firefoxService = new FirefoxServiceBuilder(geckoDriverFile).build();
|
93 |
|
94 | driver =
|
95 | require('selenium-webdriver/firefox')
|
96 | .Driver.createSession(new selenium_webdriver_1.Capabilities(this.config_.capabilities), firefoxService);
|
97 | break;
|
98 | default:
|
99 | throw new exitCodes_1.BrowserError(logger, 'browserName ' + this.config_.capabilities.browserName +
|
100 | ' is not supported with directConnect.');
|
101 | }
|
102 | this.drivers_.push(driver);
|
103 | return driver;
|
104 | }
|
105 | }
|
106 | exports.Direct = Direct;
|
107 |
|
\ | No newline at end of file |