arrow-left Back to topicQuizDownloadsCheck yourself1.You set up page.waitForEvent('download') AFTER clicking the Export button. The test hangs indefinitely. Why?The download event requires a specific timeout to be set.The download event fired before waitForEvent() started listening — the event was missed.page.waitForEvent is not the right method for downloads.You need to disable the browser's built-in download prompt first.2.Which method on the Download object returns the filename suggested by the server?download.fileName()download.suggestedFilename()download.name()download.path() — it includes the filename.3.What is the correct pattern to intercept a download triggered by a button click?Click the button, then call await page.waitForEvent('download').Call const dl = page.waitForEvent('download') (no await), click the button, then const download = await dl.Use page.on('download', handler) after the click.Use context.waitForEvent('download') instead of page.waitForEvent.4.How do you read the content of an intercepted download file in a test?const content = await download.text()const content = download.read('utf-8')const filePath = await download.path(); const content = fs.readFileSync(filePath, 'utf-8')const content = await download.body()5.One button click triggers three file downloads simultaneously. What is the best way to collect all three?Call page.waitForEvent('download') three times sequentially.Use page.on('download', handler) to collect downloads as they arrive, then poll until you have all three.Use context.waitForEvent('download') which returns an array.Multiple downloads are not supported — you must test each one in a separate test.6.How do you permanently save an intercepted download to a specific path on disk?await download.saveAs('/desired/path/file.csv')fs.copyFileSync(await download.path(), '/desired/path/file.csv')await download.moveTo('/desired/path/file.csv')Configure downloadsPath in playwright.config.ts — files go there automatically.7.You want to verify that a downloaded CSV has a header row containing 'Order ID,Customer,Status,Total'. What approach works?Use expect(download).toContainText('Order ID').Read the file with fs.readFileSync(await download.path(), 'utf-8'), split by newline, and assert on the first line.Use download.matches('Order ID,Customer,Status,Total').The Download object exposes .headers() which includes the CSV header.8.Why is the page.waitForEvent('download') pattern safer than page.on('download', handler) for a single expected download?page.on() only works for multiple downloads.waitForEvent returns a Promise you can await, making the test linear and easy to read; page.on requires manual cleanup of the listener.page.on permanently blocks all future downloads.They are identical — use either one.Submit answersarrow-left PreviousDialogsEvaluating JavaScriptNext arrow-right