2424
2525import com .google .common .collect .ImmutableMap ;
2626import com .google .common .collect .ImmutableSet ;
27+ import java .io .IOException ;
2728import java .net .MalformedURLException ;
2829import java .net .URL ;
30+ import java .nio .file .Path ;
2931import java .time .Duration ;
3032import java .util .ArrayList ;
3133import java .util .Base64 ;
5153import org .openqa .selenium .Cookie ;
5254import org .openqa .selenium .Dimension ;
5355import org .openqa .selenium .HasCapabilities ;
56+ import org .openqa .selenium .HasDownloads ;
5457import org .openqa .selenium .ImmutableCapabilities ;
5558import org .openqa .selenium .JavascriptException ;
5659import org .openqa .selenium .JavascriptExecutor ;
8285import org .openqa .selenium .interactions .Sequence ;
8386import org .openqa .selenium .internal .Debug ;
8487import org .openqa .selenium .internal .Require ;
88+ import org .openqa .selenium .io .Zip ;
8589import org .openqa .selenium .json .TypeToken ;
8690import org .openqa .selenium .logging .LocalLogs ;
8791import org .openqa .selenium .logging .LoggingHandler ;
@@ -105,6 +109,7 @@ public class RemoteWebDriver
105109 implements WebDriver ,
106110 JavascriptExecutor ,
107111 HasCapabilities ,
112+ HasDownloads ,
108113 HasFederatedCredentialManagement ,
109114 HasVirtualAuthenticator ,
110115 Interactive ,
@@ -707,6 +712,51 @@ public void removeVirtualAuthenticator(VirtualAuthenticator authenticator) {
707712 ImmutableMap .of ("authenticatorId" , authenticator .getId ()));
708713 }
709714
715+ /**
716+ * Retrieves the downloadable files as a map of file names and their corresponding URLs.
717+ *
718+ * @return A map containing file names as keys and URLs as values.
719+ * @throws WebDriverException if capability to enable downloads is not set
720+ */
721+ @ Override
722+ @ SuppressWarnings ("unchecked" )
723+ public List <String > getDownloadableFiles () {
724+ requireDownloadsEnabled (capabilities );
725+
726+ Response response = execute (DriverCommand .GET_DOWNLOADABLE_FILES );
727+ Map <String , List <String >> value = (Map <String , List <String >>) response .getValue ();
728+ return value .get ("names" );
729+ }
730+
731+ /**
732+ * Downloads a file from the specified location.
733+ *
734+ * @param fileName the name of the file to download
735+ * @param targetLocation the location where the file should be downloaded
736+ * @throws IOException if an I/O error occurs during the file download
737+ */
738+ @ SuppressWarnings ("unchecked" )
739+ @ Override
740+ public void downloadFile (String fileName , Path targetLocation ) throws IOException {
741+ requireDownloadsEnabled (capabilities );
742+
743+ Response response = execute (DriverCommand .DOWNLOAD_FILE , Map .of ("name" , fileName ));
744+ String contents = ((Map <String , String >) response .getValue ()).get ("contents" );
745+ Zip .unzip (contents , targetLocation .toFile ());
746+ }
747+
748+ /**
749+ * Deletes all downloadable files.
750+ *
751+ * @throws WebDriverException capability to enable downloads must be set
752+ */
753+ @ Override
754+ public void deleteDownloadableFiles () {
755+ requireDownloadsEnabled (capabilities );
756+
757+ execute (DriverCommand .DELETE_DOWNLOADABLE_FILES );
758+ }
759+
710760 @ Override
711761 public void setDelayEnabled (boolean enabled ) {
712762 execute (DriverCommand .SET_DELAY_ENABLED (enabled ));
0 commit comments