4
4
* it down, and setting up the driver correctly.
5
5
*/
6
6
import * as fs from 'fs' ;
7
- import * as path from 'path' ;
8
7
import { Capabilities , WebDriver } from 'selenium-webdriver' ;
9
- import { ServiceBuilder as ChromeServiceBuilder } from 'selenium-webdriver/chrome' ;
8
+ import { ServiceBuilder as ChromeServiceBuilder , Driver as DriverForChrome } from 'selenium-webdriver/chrome' ;
9
+ import { ServiceBuilder as FirefoxServiceBuilder , Driver as DriverForFirefox } from 'selenium-webdriver/firefox' ;
10
10
11
11
import { Config } from '../config' ;
12
12
import { BrowserError } from '../exitCodes' ;
13
13
import { Logger } from '../logger' ;
14
14
15
15
import { DriverProvider } from './driverProvider' ;
16
16
17
- const SeleniumConfig = require ( 'webdriver-manager/built/lib/config' ) . Config ;
17
+ import { ChromeDriver , GeckoDriver } from 'webdriver-manager-replacement' ;
18
18
19
19
let logger = new Logger ( 'direct' ) ;
20
20
export class Direct extends DriverProvider {
@@ -60,14 +60,11 @@ export class Direct extends DriverProvider {
60
60
chromeDriverFile = this . config_ . chromeDriver ;
61
61
} else {
62
62
try {
63
- let updateJson = path . resolve ( SeleniumConfig . getSeleniumDir ( ) , 'update-config.json' ) ;
64
- let updateConfig = JSON . parse ( fs . readFileSync ( updateJson ) . toString ( ) ) ;
65
- chromeDriverFile = updateConfig . chrome . last ;
63
+ chromeDriverFile = new ChromeDriver ( ) . getBinaryPath ( ) ;
66
64
} catch ( e ) {
67
65
throw new BrowserError (
68
66
logger ,
69
- 'Could not find update-config.json. ' +
70
- 'Run \'webdriver-manager update\' to download binaries.' ) ;
67
+ 'Run \'webdriver-manager update\' to download binaries.' ) ;
71
68
}
72
69
}
73
70
@@ -79,27 +76,19 @@ export class Direct extends DriverProvider {
79
76
}
80
77
81
78
let chromeService = new ChromeServiceBuilder ( chromeDriverFile ) . build ( ) ;
82
- // driver = ChromeDriver.createSession(new Capabilities(this.config_.capabilities),
83
- // chromeService);
84
- // TODO(ralphj): fix typings
85
- driver =
86
- require ( 'selenium-webdriver/chrome' )
87
- . Driver . createSession ( new Capabilities ( this . config_ . capabilities ) , chromeService ) ;
79
+ driver = DriverForChrome . createSession ( new Capabilities ( this . config_ . capabilities ) , chromeService ) ;
88
80
break ;
89
81
case 'firefox' :
90
82
let geckoDriverFile : string ;
91
83
if ( this . config_ . geckoDriver ) {
92
84
geckoDriverFile = this . config_ . geckoDriver ;
93
85
} else {
94
86
try {
95
- let updateJson = path . resolve ( SeleniumConfig . getSeleniumDir ( ) , 'update-config.json' ) ;
96
- let updateConfig = JSON . parse ( fs . readFileSync ( updateJson ) . toString ( ) ) ;
97
- geckoDriverFile = updateConfig . gecko . last ;
87
+ geckoDriverFile = new GeckoDriver ( ) . getBinaryPath ( ) ;
98
88
} catch ( e ) {
99
89
throw new BrowserError (
100
90
logger ,
101
- 'Could not find update-config.json. ' +
102
- 'Run \'webdriver-manager update\' to download binaries.' ) ;
91
+ 'Run \'webdriver-manager update\' to download binaries.' ) ;
103
92
}
104
93
}
105
94
@@ -110,14 +99,8 @@ export class Direct extends DriverProvider {
110
99
'. Run \'webdriver-manager update\' to download binaries.' ) ;
111
100
}
112
101
113
- // TODO (mgiambalvo): Turn this into an import when the selenium typings are updated.
114
- const FirefoxServiceBuilder = require ( 'selenium-webdriver/firefox' ) . ServiceBuilder ;
115
-
116
102
let firefoxService = new FirefoxServiceBuilder ( geckoDriverFile ) . build ( ) ;
117
- // TODO(mgiambalvo): Fix typings.
118
- driver =
119
- require ( 'selenium-webdriver/firefox' )
120
- . Driver . createSession ( new Capabilities ( this . config_ . capabilities ) , firefoxService ) ;
103
+ driver = DriverForFirefox . createSession ( new Capabilities ( this . config_ . capabilities ) , firefoxService ) ;
121
104
break ;
122
105
default :
123
106
throw new BrowserError (
0 commit comments