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;
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.

Further reading

Problem with a question

Playwright · Junior · question 59

Test yourself

Take the Playwright · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz