@@ -55,17 +55,51 @@ private void PopulateOptionsTypes()
5555
5656 public event EventHandler < DriverStartingEventArgs > DriverStarting ;
5757
58- public IWebDriver CreateDriver ( Type driverType )
58+ public DriverService CreateDriverService ( Type driverType )
5959 {
60- return CreateDriverWithOptions ( driverType , null ) ;
60+ DriverService service = null ;
61+
62+ if ( typeof ( ChromeDriver ) . IsAssignableFrom ( driverType ) )
63+ {
64+ service = ChromeDriverService . CreateDefaultService ( ) ;
65+ }
66+ else if ( typeof ( EdgeDriver ) . IsAssignableFrom ( driverType ) )
67+ {
68+ service = EdgeDriverService . CreateDefaultService ( ) ;
69+ }
70+ else if ( typeof ( InternetExplorerDriver ) . IsAssignableFrom ( driverType ) )
71+ {
72+ service = InternetExplorerDriverService . CreateDefaultService ( ) ;
73+ }
74+ else if ( typeof ( FirefoxDriver ) . IsAssignableFrom ( driverType ) )
75+ {
76+ service = FirefoxDriverService . CreateDefaultService ( ) ;
77+ }
78+ else if ( typeof ( SafariDriver ) . IsAssignableFrom ( driverType ) )
79+ {
80+ service = SafariDriverService . CreateDefaultService ( ) ;
81+ }
82+
83+ if ( ! String . IsNullOrEmpty ( this . driverPath ) && service != null )
84+ {
85+ service . DriverServicePath = Path . GetDirectoryName ( this . driverPath ) ;
86+ service . DriverServiceExecutableName = Path . GetFileName ( this . driverPath ) ;
87+ }
88+
89+ return service ;
6190 }
6291
63- public IWebDriver CreateDriverWithOptions ( Type driverType , DriverOptions driverOptions )
92+ public IWebDriver CreateDriver ( DriverService service , Type driverType )
93+ {
94+ return CreateDriverWithOptions ( service , driverType , null ) ;
95+ }
96+
97+ public IWebDriver CreateDriverWithOptions ( DriverService service , Type driverType , DriverOptions driverOptions )
6498 {
6599 Console . WriteLine ( $ "Creating new driver of { driverType } type...") ;
66100
67101 Browser browser = Browser . All ;
68- DriverService service = null ;
102+
69103 DriverOptions options = null ;
70104
71105 List < Type > constructorArgTypeList = new List < Type > ( ) ;
@@ -78,7 +112,6 @@ public IWebDriver CreateDriverWithOptions(Type driverType, DriverOptions driverO
78112 var chromeOptions = ( ChromeOptions ) options ;
79113 chromeOptions . AddArguments ( "--no-sandbox" , "--disable-dev-shm-usage" ) ;
80114
81- service = ChromeDriverService . CreateDefaultService ( ) ;
82115 if ( ! string . IsNullOrEmpty ( this . browserBinaryLocation ) )
83116 {
84117 ( ( ChromeOptions ) options ) . BinaryLocation = this . browserBinaryLocation ;
@@ -92,7 +125,6 @@ public IWebDriver CreateDriverWithOptions(Type driverType, DriverOptions driverO
92125 var edgeOptions = ( EdgeOptions ) options ;
93126 edgeOptions . AddArguments ( "--no-sandbox" , "--disable-dev-shm-usage" ) ;
94127
95- service = EdgeDriverService . CreateDefaultService ( ) ;
96128 if ( ! string . IsNullOrEmpty ( this . browserBinaryLocation ) )
97129 {
98130 ( ( EdgeOptions ) options ) . BinaryLocation = this . browserBinaryLocation ;
@@ -102,13 +134,11 @@ public IWebDriver CreateDriverWithOptions(Type driverType, DriverOptions driverO
102134 {
103135 browser = Browser . IE ;
104136 options = GetDriverOptions < InternetExplorerOptions > ( driverType , driverOptions ) ;
105- service = InternetExplorerDriverService . CreateDefaultService ( ) ;
106137 }
107138 else if ( typeof ( FirefoxDriver ) . IsAssignableFrom ( driverType ) )
108139 {
109140 browser = Browser . Firefox ;
110141 options = GetDriverOptions < FirefoxOptions > ( driverType , driverOptions ) ;
111- service = FirefoxDriverService . CreateDefaultService ( ) ;
112142 if ( ! string . IsNullOrEmpty ( this . browserBinaryLocation ) )
113143 {
114144 ( ( FirefoxOptions ) options ) . BinaryLocation = this . browserBinaryLocation ;
@@ -118,18 +148,12 @@ public IWebDriver CreateDriverWithOptions(Type driverType, DriverOptions driverO
118148 {
119149 browser = Browser . Safari ;
120150 options = GetDriverOptions < SafariOptions > ( driverType , driverOptions ) ;
121- service = SafariDriverService . CreateDefaultService ( ) ;
122- }
123-
124- if ( ! String . IsNullOrEmpty ( this . driverPath ) && service != null )
125- {
126- service . DriverServicePath = Path . GetDirectoryName ( this . driverPath ) ;
127- service . DriverServiceExecutableName = Path . GetFileName ( this . driverPath ) ;
128151 }
129152
130153 this . OnDriverLaunching ( service , options ) ;
131154
132155 driver = ( IWebDriver ) Activator . CreateInstance ( driverType , service , options ) ;
156+
133157 return driver ;
134158 }
135159
0 commit comments