test: add test for downloads in nested downloads (#9924)

This commit is contained in:
Max Schmitt 2021-11-01 17:45:22 +01:00 committed by GitHub
parent 6a1e075903
commit ff8494c7e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -568,6 +568,36 @@ it.describe('download event', () => {
expect(fs.readFileSync(path).toString()).toBe('Hello world'); expect(fs.readFileSync(path).toString()).toBe('Hello world');
await page.close(); await page.close();
}); });
it('should emit download event from nested iframes', async ({ server, browser, browserName }, testInfo) => {
it.fixme(browserName === 'firefox', 'https://github.com/microsoft/playwright/issues/9922');
const page = await browser.newPage({ acceptDownloads: true });
server.setRoute('/1', (req, res) => {
res.setHeader('Content-Type', 'text/html');
res.end(`<iframe src="${server.PREFIX}/2"></iframe>`);
});
server.setRoute('/2', (req, res) => {
res.setHeader('Content-Type', 'text/html');
res.end(`<iframe src="${server.PREFIX}/3"></iframe>`);
});
server.setRoute('/3', (req, res) => {
res.setHeader('Content-Type', 'text/html');
res.end(` <a href="${server.PREFIX}/download">download</a>`);
});
await page.goto(server.PREFIX + '/1');
const [download] = await Promise.all([
page.waitForEvent('download'),
page.frame({
url: server.PREFIX + '/3'
}).click('text=download')
]);
const userPath = testInfo.outputPath('download.txt');
await download.saveAs(userPath);
expect(fs.existsSync(userPath)).toBeTruthy();
expect(fs.readFileSync(userPath).toString()).toBe('Hello world');
await page.close();
});
}); });
it('should be able to download a PDF file', async ({ browser, server, asset }) => { it('should be able to download a PDF file', async ({ browser, server, asset }) => {