Playwright + JS · Lesson 23 of 35
Module 23: Browser Events & File Handling
Try it yourself
Implement validateFileSize:
The editor has a worked example. Read it, tweak it, then press Mark as complete.
// Catch console errors:
page.on("pageerror", (error) => {
console.error("Uncaught exception on page:", error.message);
});
// Download verification:
const downloadPromise = page.waitForEvent("download");
await page.getByRole("button", { name: "Download Invoice" }).click();
const download = await downloadPromise;
await download.saveAs("test-results/invoice.pdf");A comprehensive automated test does more than click buttons; it also verifies that no console errors occurred and validates downloaded files. In this lesson, we will learn how to capture browser events, intercept console logs, handle custom file uploaders, and verify downloaded documents. Let's get started!
Part of the Playwright + JS course (Playwright with JavaScript). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
Playwright stores downloads in a temporary isolated cache directory and auto-deletes them when the context closes if not saved.
Finished reading?
Review the worked example in the editor, then mark the lesson complete.