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 { Driver as DriverForChrome , ServiceBuilder as ChromeServiceBuilder } from 'selenium-webdriver/chrome' ;
9
+ import { Driver as DriverForFirefox , ServiceBuilder as FirefoxServiceBuilder } from 'selenium-webdriver/firefox' ;
10
+ import { ChromeDriver , GeckoDriver } from 'webdriver-manager-replacement' ;
10
11
11
12
import { Config } from '../config' ;
12
13
import { BrowserError } from '../exitCodes' ;
13
14
import { Logger } from '../logger' ;
14
15
15
16
import { DriverProvider } from './driverProvider' ;
16
17
17
- const SeleniumConfig = require ( 'webdriver-manager/built/lib/config' ) . Config ;
18
-
19
18
let logger = new Logger ( 'direct' ) ;
20
19
export class Direct extends DriverProvider {
21
20
constructor ( config : Config ) {
@@ -60,14 +59,10 @@ export class Direct extends DriverProvider {
60
59
chromeDriverFile = this . config_ . chromeDriver ;
61
60
} else {
62
61
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 ;
62
+ chromeDriverFile = new ChromeDriver ( ) . getBinaryPath ( ) ;
66
63
} catch ( e ) {
67
64
throw new BrowserError (
68
- logger ,
69
- 'Could not find update-config.json. ' +
70
- 'Run \'webdriver-manager update\' to download binaries.' ) ;
65
+ logger , 'Run \'webdriver-manager update\' to download binaries.' ) ;
71
66
}
72
67
}
73
68
@@ -79,27 +74,19 @@ export class Direct extends DriverProvider {
79
74
}
80
75
81
76
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 ) ;
77
+ driver = DriverForChrome . createSession (
78
+ new Capabilities ( this . config_ . capabilities ) , chromeService ) ;
88
79
break ;
89
80
case 'firefox' :
90
81
let geckoDriverFile : string ;
91
82
if ( this . config_ . geckoDriver ) {
92
83
geckoDriverFile = this . config_ . geckoDriver ;
93
84
} else {
94
85
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 ;
86
+ geckoDriverFile = new GeckoDriver ( ) . getBinaryPath ( ) ;
98
87
} catch ( e ) {
99
88
throw new BrowserError (
100
- logger ,
101
- 'Could not find update-config.json. ' +
102
- 'Run \'webdriver-manager update\' to download binaries.' ) ;
89
+ logger , 'Run \'webdriver-manager update\' to download binaries.' ) ;
103
90
}
104
91
}
105
92
@@ -110,14 +97,9 @@ export class Direct extends DriverProvider {
110
97
'. Run \'webdriver-manager update\' to download binaries.' ) ;
111
98
}
112
99
113
- // TODO (mgiambalvo): Turn this into an import when the selenium typings are updated.
114
- const FirefoxServiceBuilder = require ( 'selenium-webdriver/firefox' ) . ServiceBuilder ;
115
-
116
100
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 ) ;
101
+ driver = DriverForFirefox . createSession (
102
+ new Capabilities ( this . config_ . capabilities ) , firefoxService ) ;
121
103
break ;
122
104
default :
123
105
throw new BrowserError (
0 commit comments