Playwright · Junior · Question 59 of 75
How do you test a file download?
const download = page.waitForEvent("download");
await page.getByText("Export CSV").click();
const file = await download;- 1Downloads are blocked, so they can't be tested
- 2Wait for the
downloadevent and use the result - 3Check the user's Downloads folder after clicking
Show the answer
Correct answer: Wait for the download event and use the result
Explanation
The Download object gives the suggested file name and lets you save the file with saveAs() to check its contents.