35
35
import java .util .Arrays ;
36
36
import java .util .List ;
37
37
import java .util .Map ;
38
+ import java .util .logging .Level ;
38
39
import java .util .logging .Logger ;
39
40
40
41
import static java .nio .file .StandardCopyOption .REPLACE_EXISTING ;
@@ -59,6 +60,7 @@ public class SeleniumManager {
59
60
private static final String SELENIUM_MANAGER = "selenium-manager" ;
60
61
private static final String EXE = ".exe" ;
61
62
private static final String WARN = "WARN" ;
63
+ private static final String DEBUG = "DEBUG" ;
62
64
63
65
private static SeleniumManager manager ;
64
66
@@ -94,6 +96,7 @@ public static SeleniumManager getInstance() {
94
96
* @return the standard output of the execution.
95
97
*/
96
98
private static String runCommand (String ... command ) {
99
+ LOG .fine (String .format ("Executing Process: %s" , command ));
97
100
String output = "" ;
98
101
int code = 0 ;
99
102
try {
@@ -120,8 +123,14 @@ private static String runCommand(String... command) {
120
123
"\n " + jsonOutput .result .message );
121
124
}
122
125
jsonOutput .logs .stream ()
123
- .filter (log -> log .level .equalsIgnoreCase (WARN ))
124
- .forEach (log -> LOG .warning (log .message ));
126
+ .forEach (logged -> {
127
+ if (logged .level .equalsIgnoreCase (WARN )) {
128
+ LOG .warning (logged .message );
129
+ }
130
+ if (logged .level .equalsIgnoreCase (DEBUG )) {
131
+ LOG .fine (logged .message );
132
+ }
133
+ });
125
134
return jsonOutput .result .message ;
126
135
}
127
136
@@ -187,24 +196,34 @@ private String getBrowserBinary(Capabilities options) {
187
196
* @return the location of the driver.
188
197
*/
189
198
public String getDriverPath (Capabilities options ) {
190
- File binaryFile = getBinary ();
199
+ LOG .info ("applicable driver not found; attempting to install with Selenium Manager (Beta)" );
200
+ File binaryFile = getBinary ();
191
201
if (binaryFile == null ) {
192
202
return null ;
193
203
}
194
- List <String > commandList = new ArrayList <>(
195
- Arrays .asList (binaryFile .getAbsolutePath (),
196
- "--browser" ,
197
- options .getBrowserName (),
198
- "--output" , "json" ));
204
+ List <String > commandList = new ArrayList <>();
205
+ commandList .add (binaryFile .getAbsolutePath ());
206
+ commandList .add ("--browser" );
207
+ commandList .add (options .getBrowserName ());
208
+ commandList .add ("--output" );
209
+ commandList .add ("json" );
199
210
if (!options .getBrowserVersion ().isEmpty ()) {
200
- commandList .addAll (Arrays .asList ("--browser-version" , options .getBrowserVersion ()));
211
+ commandList .add ("--browser-version" );
212
+ commandList .add (options .getBrowserVersion ());
201
213
}
202
214
203
215
String browserBinary = getBrowserBinary (options );
204
216
if (browserBinary != null && !browserBinary .isEmpty ()) {
205
- commandList .addAll (Arrays .asList ("--browser-path" , browserBinary ));
217
+ commandList .add ("--browser-path" );
218
+ commandList .add (browserBinary );
219
+ }
220
+
221
+ if (LOG .getLevel ().intValue () > Level .FINE .intValue ()) {
222
+ commandList .add ("--verbose" );
206
223
}
207
224
208
- return runCommand (commandList .toArray (new String [0 ]));
225
+ String path = runCommand (commandList .toArray (new String [0 ]));
226
+ LOG .fine (String .format ("Using driver at location: %s" , path ));
227
+ return path ;
209
228
}
210
229
}
0 commit comments