Reputation: 11
Actually i'm working on one of the project where 'CSV download' button is working but api is not called so my question is >> How can i verify that when i click on the 'CSV download' button and CSV is downloaded.
I'm creating automation script with playwright where i have to expect that 'Download CSV' button is working or not
Upvotes: 0
Views: 203
Reputation: 1102
Regardless of how the download is triggered (via API, or static js on the page)- you can leverage the download event to catch the CSV being downloaded. Here is an example:
// Start waiting for download before clicking. Note no await.
const downloadPromise = page.waitForEvent('download');
// Trigger download
await page.getByText('CSV download').click();
// Wait for the download process to complete
const download = await downloadPromise;
const tempPath = await download.path();
// Check it is a csv
expect(tempPath.endsWith('.csv')).toBeTruthy();
Upvotes: 0