diff --git a/java/test/org/openqa/selenium/grid/router/RemoteWebDriverDownloadTest.java b/java/test/org/openqa/selenium/grid/router/RemoteWebDriverDownloadTest.java index c8cea51cbaecb..3f0d7d1d3e8ec 100644 --- a/java/test/org/openqa/selenium/grid/router/RemoteWebDriverDownloadTest.java +++ b/java/test/org/openqa/selenium/grid/router/RemoteWebDriverDownloadTest.java @@ -30,6 +30,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Objects; +import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import org.junit.jupiter.api.AfterEach; @@ -57,6 +58,8 @@ class RemoteWebDriverDownloadTest { + private static final Set FILE_EXTENSIONS = Set.of(".txt", ".jpg"); + private Server server; private NettyAppServer appServer; private Capabilities capabilities; @@ -112,7 +115,15 @@ void canListDownloadedFiles() { driver.findElement(By.id("file-2")).click(); new WebDriverWait(driver, Duration.ofSeconds(5)) - .until(d -> ((HasDownloads) d).getDownloadableFiles().size() == 2); + .until( + d -> + ((HasDownloads) d) + .getDownloadableFiles().stream() + // ensure we hit no temporary file created by the browser while + // downloading + .filter((f) -> FILE_EXTENSIONS.stream().anyMatch(f::endsWith)) + .count() + == 2); List downloadableFiles = ((HasDownloads) driver).getDownloadableFiles(); assertThat(downloadableFiles).contains("file_1.txt", "file_2.jpg"); @@ -132,7 +143,12 @@ void canDownloadFiles() throws IOException { driver.findElement(By.id("file-1")).click(); new WebDriverWait(driver, Duration.ofSeconds(5)) - .until(d -> !((HasDownloads) d).getDownloadableFiles().isEmpty()); + .until( + d -> + ((HasDownloads) d) + .getDownloadableFiles().stream() + // ensure we hit no temporary file created by the browser while downloading + .anyMatch((f) -> FILE_EXTENSIONS.stream().anyMatch(f::endsWith))); String fileName = ((HasDownloads) driver).getDownloadableFiles().get(0); @@ -155,7 +171,12 @@ void testCanDeleteFiles() { driver.findElement(By.id("file-1")).click(); new WebDriverWait(driver, Duration.ofSeconds(5)) - .until(d -> !((HasDownloads) d).getDownloadableFiles().isEmpty()); + .until( + d -> + ((HasDownloads) d) + .getDownloadableFiles().stream() + // ensure we hit no temporary file created by the browser while downloading + .anyMatch((f) -> FILE_EXTENSIONS.stream().anyMatch(f::endsWith))); driver = new Augmenter().augment(driver); ((HasDownloads) driver).deleteDownloadableFiles();