Skip to content

Commit 15b44c0

Browse files
committed
[java] make RemoteWebDriverDownloadTest less flaky
1 parent 34d3ff8 commit 15b44c0

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.LinkedList;
3131
import java.util.List;
3232
import java.util.Objects;
33+
import java.util.Set;
3334
import java.util.concurrent.ExecutorService;
3435
import java.util.concurrent.Executors;
3536
import org.junit.jupiter.api.AfterEach;
@@ -57,6 +58,8 @@
5758

5859
class RemoteWebDriverDownloadTest {
5960

61+
private static final Set<String> FILE_EXTENSIONS = Set.of(".txt", ".jpg");
62+
6063
private Server<?> server;
6164
private NettyAppServer appServer;
6265
private Capabilities capabilities;
@@ -112,7 +115,15 @@ void canListDownloadedFiles() {
112115
driver.findElement(By.id("file-2")).click();
113116

114117
new WebDriverWait(driver, Duration.ofSeconds(5))
115-
.until(d -> ((HasDownloads) d).getDownloadableFiles().size() == 2);
118+
.until(
119+
d ->
120+
((HasDownloads) d)
121+
.getDownloadableFiles().stream()
122+
// ensure we hit no temporary file created by the browser while
123+
// downloading
124+
.filter((f) -> FILE_EXTENSIONS.stream().anyMatch(f::endsWith))
125+
.count()
126+
== 2);
116127

117128
List<String> downloadableFiles = ((HasDownloads) driver).getDownloadableFiles();
118129
assertThat(downloadableFiles).contains("file_1.txt", "file_2.jpg");
@@ -132,7 +143,12 @@ void canDownloadFiles() throws IOException {
132143
driver.findElement(By.id("file-1")).click();
133144

134145
new WebDriverWait(driver, Duration.ofSeconds(5))
135-
.until(d -> !((HasDownloads) d).getDownloadableFiles().isEmpty());
146+
.until(
147+
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)));
136152

137153
String fileName = ((HasDownloads) driver).getDownloadableFiles().get(0);
138154

@@ -155,7 +171,12 @@ void testCanDeleteFiles() {
155171
driver.findElement(By.id("file-1")).click();
156172

157173
new WebDriverWait(driver, Duration.ofSeconds(5))
158-
.until(d -> !((HasDownloads) d).getDownloadableFiles().isEmpty());
174+
.until(
175+
d ->
176+
((HasDownloads) d)
177+
.getDownloadableFiles().stream()
178+
// ensure we hit no temporary file created by the browser while downloading
179+
.anyMatch((f) -> FILE_EXTENSIONS.stream().anyMatch(f::endsWith)));
159180

160181
driver = new Augmenter().augment(driver);
161182
((HasDownloads) driver).deleteDownloadableFiles();

0 commit comments

Comments
 (0)