My test code looks like
test("can download the excel file", async ({ page }) => {
await page.goto("/download-page");
const downloadPromise = page.waitForEvent("download");
await page.getByRole("button", { name: "Download", exact: true }).click();
const download = await downloadPromise;
await download.saveAs(path.join(__dirname, "downloads", download.suggestedFilename()));
When executing this on my machine it works perfectly fine. However, when executing in in a github action it fails with the error
Error: download.saveAs: canceled
114 | await page.getByRole("button", { name: "Download", exact: true }).click();
115 | const download = await downloadPromise;
> 116 | await download.saveAs(path.join(__dirname, "downloads", download.suggestedFilename()));
| ^
The github action is using the following image: mcr.microsoft.com/playwright:v1.49.0-jammy
The code executed when the "Download Button" is clicked looks liek
const link = document.createElement("a");
link.href = `/path-to-my-file-xlsx`;
link.download = `template.xlsx`;
link.click();
I'm running out of ideas as I already checked tracer etc. - I don't seem to get a more detailed error message than this.
UPDATE:
Debug logs show the following output
pw:api => download.saveAs started +1ms
pw:api => download.saveAs started +1ms
pw:api <= download.saveAs failed +5ms
pw:api <= download.saveAs failed +5ms
As it cancels already after 5ms I'd suppose the browser actually prevents the download ... But I cannot find out why.
I finally found out that the issue is not within playwright but my test setup. The download did not work at all (the backend replied with an error).
In my case the backend generates an excel that should be downloaded - if the generation fails the error
Error: download.saveAs: canceled
Will be shown.
I'll not delete the question as it might help others to find the same issue.