2727import org .openqa .selenium .remote .service .DriverService ;
2828
2929import java .io .File ;
30+ import java .io .FileOutputStream ;
3031import java .io .IOException ;
3132import java .net .MalformedURLException ;
3233
@@ -78,6 +79,7 @@ public static class Builder extends DriverService.Builder<
7879 GeckoDriverService , GeckoDriverService .Builder > {
7980
8081 private FirefoxBinary binary ;
82+
8183 public Builder () {
8284 this (new FirefoxBinary ());
8385 }
@@ -101,10 +103,6 @@ protected File findDefaultExecutable() {
101103 protected ImmutableList <String > createArgs () {
102104 ImmutableList .Builder <String > argsBuilder = ImmutableList .builder ();
103105 argsBuilder .add (String .format ("--port=%d" , getPort ()));
104- if (getLogFile () != null ) {
105- // TODO: watch https://github.com/mozilla/geckodriver/issues/415
106- //argsBuilder.add(String.format("--log-file=\"%s\"", getLogFile().getAbsolutePath()));
107- }
108106 try {
109107 argsBuilder .add ("-b" );
110108 argsBuilder .add (binary .getPath ());
@@ -117,10 +115,23 @@ protected ImmutableList<String> createArgs() {
117115
118116 @ Override
119117 protected GeckoDriverService createDriverService (File exe , int port ,
120- ImmutableList <String > args ,
121- ImmutableMap <String , String > environment ) {
118+ ImmutableList <String > args ,
119+ ImmutableMap <String , String > environment ) {
122120 try {
123- return new GeckoDriverService (exe , port , args , environment );
121+ GeckoDriverService service = new GeckoDriverService (exe , port , args , environment );
122+ if (getLogFile () != null ) {
123+ service .sendOutputTo (new FileOutputStream (getLogFile ()));
124+ } else {
125+ String firefoxLogFile = System .getProperty (FirefoxDriver .SystemProperty .BROWSER_LOGFILE );
126+ if (firefoxLogFile != null ) {
127+ if ("/dev/stdout" .equals (firefoxLogFile )) {
128+ service .sendOutputTo (System .out );
129+ }
130+ service .sendOutputTo (new FileOutputStream (firefoxLogFile ));
131+ }
132+
133+ }
134+ return service ;
124135 } catch (IOException e ) {
125136 throw new WebDriverException (e );
126137 }
0 commit comments