13. Event Listeners, Console Errors & File Handling

Downloads and Console Listeners

// Catch page errors:
page.onPageError(error -> System.err.println("Page JS error: " + error));

// Download file and save to disk:
Download download = page.waitForDownload(() -> {
page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Export")).click();
});
Path targetPath = Paths.get("target/downloads/" + download.suggestedFilename());
download.saveAs(targetPath);

Task

  • Implement isFileNonEmpty:
  • 1. Accept long sizeBytes.
  • 2. Return sizeBytes > 0.
πŸ’‘Common doubts
Did you like the problem?
Lesson 13 of 18
Java
Loading code editor…
Next