|
17 | 17 |
|
18 | 18 | package org.openqa.selenium.grid.router; |
19 | 19 |
|
| 20 | +import static java.util.stream.Collectors.toList; |
20 | 21 | import static org.assertj.core.api.Assertions.assertThat; |
21 | 22 | import static org.openqa.selenium.HasDownloads.DownloadedFile; |
22 | 23 | import static org.openqa.selenium.remote.CapabilityType.ENABLE_DOWNLOADS; |
|
36 | 37 | import java.util.Set; |
37 | 38 | import java.util.concurrent.ExecutorService; |
38 | 39 | import java.util.concurrent.Executors; |
39 | | -import java.util.stream.Collectors; |
40 | | - |
41 | 40 | import org.junit.jupiter.api.*; |
42 | 41 | import org.openqa.selenium.*; |
43 | 42 | import org.openqa.selenium.chrome.ChromeOptions; |
@@ -111,21 +110,26 @@ void canListDownloadedFiles() { |
111 | 110 | driver.findElement(By.id("file-2")).click(); |
112 | 111 |
|
113 | 112 | HasDownloads hasDownloads = (HasDownloads) driver; |
114 | | - new WebDriverWait(driver, Duration.ofSeconds(5)) |
| 113 | + new WebDriverWait(driver, Duration.ofSeconds(5), Duration.ofMillis(50)) |
115 | 114 | .until( |
116 | | - d -> |
117 | | - hasDownloads.getDownloadableFiles().stream() |
118 | | - // ensure we hit no temporary file created by the browser while |
119 | | - // downloading |
120 | | - .filter((f) -> FILE_EXTENSIONS.stream().anyMatch(f::endsWith)) |
121 | | - .count() |
122 | | - == 2); |
| 115 | + d -> { |
| 116 | + List<String> files = hasDownloads.getDownloadableFiles(); |
| 117 | + List<String> matchingFiles = |
| 118 | + files.stream() |
| 119 | + .filter((f) -> FILE_EXTENSIONS.stream().anyMatch(f::endsWith)) |
| 120 | + .collect(toList()); |
| 121 | + System.out.printf( |
| 122 | + "[*****] FOUND %s FILES: %s; MATCHING %s FILES: %s%n", |
| 123 | + files.size(), files, matchingFiles.size(), matchingFiles); |
| 124 | + // ensure we hit no temporary file created by the browser while downloading |
| 125 | + return matchingFiles.size() == 2; |
| 126 | + }); |
123 | 127 |
|
124 | 128 | List<String> downloadableFiles = hasDownloads.getDownloadableFiles(); |
125 | 129 | assertThat(downloadableFiles).contains("file_1.txt", "file_2.jpg"); |
126 | 130 |
|
127 | 131 | List<DownloadedFile> downloadedFiles = hasDownloads.getDownloadedFiles(); |
128 | | - assertThat(downloadedFiles.stream().map(f -> f.getName()).collect(Collectors.toList())) |
| 132 | + assertThat(downloadedFiles.stream().map(f -> f.getName()).collect(toList())) |
129 | 133 | .contains("file_1.txt", "file_2.jpg"); |
130 | 134 |
|
131 | 135 | driver.quit(); |
|
0 commit comments