Skip to content

Commit 6e61cde

Browse files
authored
test: add test to make sure that 'download' attr is respected (#5538)
References #5537 Fixes #5396
1 parent 65bf44d commit 6e61cde

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/download.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,35 @@ describe('download event', () => {
6262
await page.close();
6363
});
6464

65+
it('should report proper download url when download is from download attribute', (test, {browserName}) => {
66+
// @see https://github.com/microsoft/playwright/issues/5537
67+
test.fixme(browserName === 'webkit');
68+
}, async ({browser, server}) => {
69+
const page = await browser.newPage({ acceptDownloads: true });
70+
await page.goto(server.PREFIX + '/empty.html');
71+
await page.setContent(`<a href="${server.PREFIX}/chromium-linux.zip" download="foo.zip">download</a>`);
72+
const [ download ] = await Promise.all([
73+
page.waitForEvent('download'),
74+
page.click('a')
75+
]);
76+
expect(download.url()).toBe(`${server.PREFIX}/chromium-linux.zip`);
77+
await page.close();
78+
});
79+
80+
it('should report downloads for download attribute', async ({browser, server}) => {
81+
const page = await browser.newPage({ acceptDownloads: true });
82+
await page.goto(server.PREFIX + '/empty.html');
83+
await page.setContent(`<a href="${server.PREFIX}/chromium-linux.zip" download="foo.zip">download</a>`);
84+
const [ download ] = await Promise.all([
85+
page.waitForEvent('download'),
86+
page.click('a')
87+
]);
88+
expect(download.suggestedFilename()).toBe(`foo.zip`);
89+
const path = await download.path();
90+
expect(fs.existsSync(path)).toBeTruthy();
91+
await page.close();
92+
});
93+
6594
it('should save to user-specified path', async ({testInfo, browser, server}) => {
6695
const page = await browser.newPage({ acceptDownloads: true });
6796
await page.setContent(`<a href="${server.PREFIX}/download">download</a>`);

0 commit comments

Comments
 (0)