Skip to content

Commit b0a8032

Browse files
committed
log the found files during download
1 parent 8db1cb1 commit b0a8032

File tree

1 file changed

+58
-23
lines changed

1 file changed

+58
-23
lines changed

java/test/org/openqa/selenium/grid/router/RemoteWebDriverDownloadTest.java

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.openqa.selenium.grid.router;
1919

20+
import static java.util.stream.Collectors.toList;
2021
import static org.assertj.core.api.Assertions.assertThat;
2122
import static org.openqa.selenium.HasDownloads.DownloadedFile;
2223
import static org.openqa.selenium.remote.CapabilityType.ENABLE_DOWNLOADS;
@@ -36,8 +37,6 @@
3637
import java.util.Set;
3738
import java.util.concurrent.ExecutorService;
3839
import java.util.concurrent.Executors;
39-
import java.util.stream.Collectors;
40-
4140
import org.junit.jupiter.api.*;
4241
import org.openqa.selenium.*;
4342
import org.openqa.selenium.chrome.ChromeOptions;
@@ -98,7 +97,7 @@ public void tearDown() {
9897
executor.shutdownNow();
9998
}
10099

101-
@Test
100+
@RepeatedTest(10)
102101
@Ignore(IE)
103102
@Ignore(SAFARI)
104103
void canListDownloadedFiles() {
@@ -111,27 +110,32 @@ void canListDownloadedFiles() {
111110
driver.findElement(By.id("file-2")).click();
112111

113112
HasDownloads hasDownloads = (HasDownloads) driver;
114-
new WebDriverWait(driver, Duration.ofSeconds(5))
113+
new WebDriverWait(driver, Duration.ofSeconds(5), Duration.ofMillis(50))
115114
.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+
});
123127

124128
List<String> downloadableFiles = hasDownloads.getDownloadableFiles();
125129
assertThat(downloadableFiles).contains("file_1.txt", "file_2.jpg");
126130

127131
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()))
129133
.contains("file_1.txt", "file_2.jpg");
130134

131135
driver.quit();
132136
}
133137

134-
@RepeatedTest(20)
138+
@RepeatedTest(10)
135139
@Ignore(IE)
136140
@Ignore(SAFARI)
137141
void canDownloadFiles() throws IOException {
@@ -142,20 +146,36 @@ void canDownloadFiles() throws IOException {
142146
driver.get(appServer.whereIs("downloads/download.html"));
143147
driver.findElement(By.id("file-1")).click();
144148

145-
new WebDriverWait(driver, Duration.ofSeconds(5))
149+
new WebDriverWait(driver, Duration.ofSeconds(5), Duration.ofMillis(50))
146150
.until(
147151
d ->
148-
((HasDownloads) d)
149-
.getDownloadableFiles().stream()
150-
// ensure we hit no temporary file created by the browser while downloading
151-
.anyMatch((f) -> FILE_EXTENSIONS.stream().anyMatch(f::endsWith)));
152+
{
153+
List<String> files = ((HasDownloads) d).getDownloadableFiles();
154+
List<String> matchingFiles = files.stream()
155+
.filter((f) -> FILE_EXTENSIONS.stream().anyMatch(f::endsWith))
156+
.collect(toList());
157+
System.out.printf(
158+
"[*****] FOUND %s FILES: %s; MATCHING %s FILES: %s%n",
159+
files.size(), files, matchingFiles.size(), matchingFiles);
160+
161+
// ensure we hit no temporary file created by the browser while downloading
162+
return !matchingFiles.isEmpty();
163+
});
152164

153165
DownloadedFile file = ((HasDownloads) driver).getDownloadedFiles().get(0);
154166

155167
Path targetLocation = Files.createTempDirectory("download");
168+
System.out.printf(
169+
"[*****] DOWNLOADING FILE %s (size: %s) into %s...%n",
170+
file.getName(), file.getSize(), targetLocation.toAbsolutePath());
171+
156172
((HasDownloads) driver).downloadFile(file.getName(), targetLocation);
157173

158174
File localFile = targetLocation.resolve(file.getName()).toFile();
175+
System.out.printf(
176+
"[*****] DOWNLOADED FILE %s (size: %s) as %s (size: %s)...%n",
177+
file.getName(), file.getSize(), localFile.getAbsolutePath(), localFile.length());
178+
159179
assertThat(localFile).hasName(file.getName());
160180
assertThat(localFile).hasSize(file.getSize());
161181
assertThat(localFile).content().isEqualToIgnoringNewLines("Hello, World!");
@@ -175,16 +195,31 @@ void testCanDeleteFiles() {
175195
new WebDriverWait(driver, Duration.ofSeconds(5))
176196
.until(
177197
d ->
178-
((HasDownloads) d)
179-
.getDownloadableFiles().stream()
180-
// ensure we hit no temporary file created by the browser while downloading
181-
.anyMatch((f) -> FILE_EXTENSIONS.stream().anyMatch(f::endsWith)));
198+
{
199+
List<String> files = ((HasDownloads) d).getDownloadableFiles();
200+
// ensure we hit no temporary file created by the browser while downloading
201+
List<String> matchingFiles = files.stream()
202+
.filter((f) -> FILE_EXTENSIONS.stream().anyMatch(f::endsWith))
203+
.collect(toList());
204+
205+
System.out.printf(
206+
"[*****] FOUND %s FILES: %s; MATCHING %s FILES: %s%n",
207+
files.size(), files, matchingFiles.size(), matchingFiles);
182208

209+
return !matchingFiles.isEmpty();
210+
});
211+
212+
System.out.printf("[*****] Augmenting webdriver...%n");
183213
driver = new Augmenter().augment(driver);
214+
215+
System.out.printf("[*****] Deleting all downloaded files...%n");
184216
((HasDownloads) driver).deleteDownloadableFiles();
185217

186218
List<String> afterDeleteNames = ((HasDownloads) driver).getDownloadableFiles();
187-
assertThat(afterDeleteNames.isEmpty()).isTrue();
219+
System.out.printf(
220+
"[*****] FOUND %s DOWNLOADED FILES: %s%n",
221+
afterDeleteNames.size(), afterDeleteNames);
222+
assertThat(afterDeleteNames).isEmpty();
188223

189224
driver.quit();
190225
}

0 commit comments

Comments
 (0)