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/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.
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/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.
Share Improve this question edited Nov 21, 2024 at 7:25 Frnak asked Nov 20, 2024 at 14:56 FrnakFrnak 6,8226 gold badges37 silver badges74 bronze badges 6 | Show 1 more comment1 Answer
Reset to default 1I 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.
DEBUG=pw:api npx playwright test
– HemChe Commented Nov 20, 2024 at 19:03