1
0
mirror of synced 2026-08-05 06:56:56 +00:00

test: navigate to download url (#558)

This commit is contained in:
Yury Semikhatsky
2021-08-13 09:05:40 -07:00
committed by GitHub
parent 70b9e2e034
commit 08776552da
@@ -73,6 +73,42 @@ public class TestDownload extends TestBase {
}
@Test
void shouldReportDownloadWhenNavigationTurnsIntoDownload() throws IOException {
Page page = browser.newPage(new Browser.NewPageOptions().setAcceptDownloads(true));
Response[] response = new Response[]{null};
PlaywrightException[] error = new PlaywrightException[]{null};
Download download = page.waitForDownload(() -> {
try {
response[0] = page.navigate(server.PREFIX + "/download");
} catch (PlaywrightException e) {
error[0] = e;
}
});
assertEquals(page, download.page());
assertEquals(server.PREFIX + "/download", download.url());
Path path = download.path();
assertTrue(Files.exists(path));
byte[] bytes = readAllBytes(path);
assertEquals("Hello world", new String(bytes, UTF_8));
if (isChromium()) {
assertNotNull(error[0]);
assertTrue(error[0].getMessage().contains("net::ERR_ABORTED"));
assertEquals("about:blank", page.url());
} else if (isWebKit()) {
assertNotNull(error[0]);
assertTrue(error[0].getMessage().contains("Download is starting"));
assertEquals("about:blank", page.url());
} else {
assertNotNull(response[0]);
assertEquals(200, response[0].status());
assertEquals(server.PREFIX + "/download", page.url());
}
page.close();
}
@Test
void shouldReportDownloadsWithAcceptDownloadsFalse() {
page.setContent("<a href='" + server.PREFIX + "/downloadWithFilename'>download</a>");