|
18 | 18 | package org.openqa.selenium.remote; |
19 | 19 |
|
20 | 20 | import static java.util.Collections.singleton; |
| 21 | +import static java.util.Objects.requireNonNull; |
21 | 22 | import static java.util.concurrent.TimeUnit.SECONDS; |
22 | 23 | import static java.util.logging.Level.SEVERE; |
23 | | -import static org.openqa.selenium.HasDownloads.DownloadedFile; |
24 | 24 | import static org.openqa.selenium.remote.CapabilityType.PLATFORM_NAME; |
25 | 25 |
|
26 | 26 | import java.io.BufferedInputStream; |
|
69 | 69 | import org.openqa.selenium.SearchContext; |
70 | 70 | import org.openqa.selenium.SessionNotCreatedException; |
71 | 71 | import org.openqa.selenium.TakesScreenshot; |
| 72 | +import org.openqa.selenium.UnsupportedCommandException; |
72 | 73 | import org.openqa.selenium.WebDriver; |
73 | 74 | import org.openqa.selenium.WebDriverException; |
74 | 75 | import org.openqa.selenium.WebElement; |
|
83 | 84 | import org.openqa.selenium.interactions.Sequence; |
84 | 85 | import org.openqa.selenium.internal.Debug; |
85 | 86 | import org.openqa.selenium.internal.Require; |
| 87 | +import org.openqa.selenium.io.Zip; |
86 | 88 | import org.openqa.selenium.logging.LocalLogs; |
87 | 89 | import org.openqa.selenium.logging.LoggingHandler; |
88 | 90 | import org.openqa.selenium.logging.Logs; |
@@ -730,12 +732,24 @@ public List<DownloadedFile> getDownloadedFiles() { |
730 | 732 | public void downloadFile(String fileName, Path targetLocation) throws IOException { |
731 | 733 | requireDownloadsEnabled(capabilities); |
732 | 734 |
|
733 | | - Response response = execute(DriverCommand.GET_DOWNLOADED_FILE, Map.of("name", fileName)); |
| 735 | + try { |
| 736 | + Response response = execute(DriverCommand.GET_DOWNLOADED_FILE, Map.of("name", fileName)); |
| 737 | + |
| 738 | + Contents.Supplier content = (Contents.Supplier) response.getValue(); |
| 739 | + try (InputStream fileContent = content.get()) { |
| 740 | + Files.createDirectories(targetLocation); |
| 741 | + Files.copy(new BufferedInputStream(fileContent), targetLocation.resolve(fileName)); |
| 742 | + } |
| 743 | + } catch (UnsupportedCommandException e) { |
| 744 | + String error = requireNonNull(e.getMessage(), e.toString()).split("\n", 2)[0]; |
| 745 | + LOG.log( |
| 746 | + Level.WARNING, |
| 747 | + "You have too old Selenium Grid version, please upgrade it. Caused by: {0}", |
| 748 | + error); |
734 | 749 |
|
735 | | - Contents.Supplier content = (Contents.Supplier) response.getValue(); |
736 | | - try (InputStream fileContent = content.get()) { |
737 | | - Files.createDirectories(targetLocation); |
738 | | - Files.copy(new BufferedInputStream(fileContent), targetLocation.resolve(fileName)); |
| 750 | + Response response = execute(DriverCommand.DOWNLOAD_FILE, Map.of("name", fileName)); |
| 751 | + String contents = ((Map<String, String>) response.getValue()).get("contents"); |
| 752 | + Zip.unzip(contents, targetLocation.toFile()); |
739 | 753 | } |
740 | 754 | } |
741 | 755 |
|
|
0 commit comments