6363import org .openqa .selenium .io .Zip ;
6464import org .openqa .selenium .json .Json ;
6565import org .openqa .selenium .remote .SessionId ;
66- import org .openqa .selenium .remote .http .Contents ;
6766import org .openqa .selenium .remote .http .HttpRequest ;
6867import org .openqa .selenium .remote .http .HttpResponse ;
6968import org .openqa .selenium .remote .tracing .AttributeKey ;
@@ -123,7 +122,7 @@ public class LocalNode extends Node {
123122 private final int maxSessionCount ;
124123 private final int configuredSessionCount ;
125124 private final boolean cdpEnabled ;
126- private final String downloadsDir ;
125+ private final String downloadsPath ;
127126
128127 private final boolean bidiEnabled ;
129128 private final AtomicBoolean drainAfterSessions = new AtomicBoolean ();
@@ -148,7 +147,7 @@ private LocalNode(
148147 Duration heartbeatPeriod ,
149148 List <SessionSlot > factories ,
150149 Secret registrationSecret ,
151- String downloadsDir ) {
150+ String downloadsPath ) {
152151 super (tracer , new NodeId (UUID .randomUUID ()), uri , registrationSecret );
153152
154153 this .bus = Require .nonNull ("Event bus" , bus );
@@ -165,7 +164,7 @@ private LocalNode(
165164 this .sessionCount .set (drainAfterSessionCount );
166165 this .cdpEnabled = cdpEnabled ;
167166 this .bidiEnabled = bidiEnabled ;
168- this .downloadsDir = Optional .ofNullable (downloadsDir ).orElse ("" );
167+ this .downloadsPath = Optional .ofNullable (downloadsPath ).orElse ("" );
169168
170169 this .healthCheck = healthCheck == null ?
171170 () -> {
@@ -180,10 +179,8 @@ private LocalNode(
180179 .ticker (ticker )
181180 .removalListener ((RemovalListener <SessionId , TemporaryFilesystem >) notification -> {
182181 TemporaryFilesystem tempFS = notification .getValue ();
183- if (tempFS != null ) {
184- tempFS .deleteTemporaryFiles ();
185- tempFS .deleteBaseDir ();
186- }
182+ tempFS .deleteTemporaryFiles ();
183+ tempFS .deleteBaseDir ();
187184 })
188185 .build ();
189186
@@ -485,17 +482,18 @@ public HttpResponse downloadFile(HttpRequest req, SessionId id) {
485482 if (slot != null && slot .getSession () instanceof DockerSession ) {
486483 return executeWebDriverCommand (req );
487484 }
488- if (this .downloadsDir .isEmpty ()) {
489- throw new WebDriverException (
490- "Please specify the directory that would contain downloaded files and restart the node." );
485+ if (this .downloadsPath .isEmpty ()) {
486+ String msg = "Please specify the path wherein the files downloaded using the browser "
487+ + "would be available via the command line arg [--downloads-path] and restart the node" ;
488+ throw new WebDriverException (msg );
491489 }
492- File dir = new File (this .downloadsDir );
490+ File dir = new File (this .downloadsPath );
493491 if (!dir .exists ()) {
494492 throw new WebDriverException (
495- String .format ("Cannot locate downloads directory %s." , downloadsDir ));
493+ String .format ("Cannot locate downloads directory %s." , downloadsPath ));
496494 }
497495 if (!dir .isDirectory ()) {
498- throw new WebDriverException (String .format ("Invalid directory: %s." ,downloadsDir ));
496+ throw new WebDriverException (String .format ("Invalid directory: %s." , downloadsPath ));
499497 }
500498 String filename = req .getQueryParameter ("filename" );
501499 try {
@@ -504,13 +502,13 @@ public HttpResponse downloadFile(HttpRequest req, SessionId id) {
504502 ).orElse (new File []{});
505503 if (allFiles .length == 0 ) {
506504 throw new WebDriverException (
507- String .format ("Cannot find file [%s] in directory %s." , filename , downloadsDir ));
505+ String .format ("Cannot find file [%s] in directory %s." , filename , downloadsPath ));
508506 }
509507 if (allFiles .length != 1 ) {
510508 throw new WebDriverException (
511509 String .format ("Expected there to be only 1 file. There were: %s." , allFiles .length ));
512510 }
513- String content = Contents . string (allFiles [0 ]);
511+ String content = Zip . zip (allFiles [0 ]);
514512 ImmutableMap <String , Object > result = ImmutableMap .of (
515513 "filename" , filename ,
516514 "contents" , content );
0 commit comments