mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 05:37:20 +03:00
parent
471ccc72d3
commit
dc23c567c4
29
test/assets/download-blob.html
Normal file
29
test/assets/download-blob.html
Normal file
@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Blob Download Example</title>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
const download = (data, filename) => {
|
||||
const a = document.createElement("a");
|
||||
a.style = "display: none";
|
||||
document.body.appendChild(a);
|
||||
a.style = "display: none";
|
||||
|
||||
const blob = new Blob([data], { type: "octet/stream" });
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
document.body.removeChild(a);
|
||||
};
|
||||
|
||||
const downloadIt = () => {
|
||||
download("Hello world", "example.txt");
|
||||
}
|
||||
</script>
|
||||
<a onclick="javascipt:downloadIt();">Download</a>
|
||||
</body>
|
||||
</html>
|
@ -70,16 +70,29 @@ describe('Download', function() {
|
||||
expect(fs.readFileSync(path).toString()).toBe('Hello world');
|
||||
await page.close();
|
||||
});
|
||||
it(`should report download path within page.on('download', …) handler`, async({browser, server}) => {
|
||||
it(`should report download path within page.on('download', …) handler for Files`, async({browser, server}) => {
|
||||
const page = await browser.newPage({ acceptDownloads: true });
|
||||
const onDownloadPathPath = new Promise((res) => {
|
||||
const onDownloadPath = new Promise((res) => {
|
||||
page.on('download', dl => {
|
||||
dl.path().then(res);
|
||||
});
|
||||
});
|
||||
await page.setContent(`<a href="${server.PREFIX}/download">download</a>`);
|
||||
await page.click('a');
|
||||
const path = await onDownloadPathPath;
|
||||
const path = await onDownloadPath;
|
||||
expect(fs.readFileSync(path).toString()).toBe('Hello world');
|
||||
await page.close();
|
||||
})
|
||||
it.fail(FFOX || WEBKIT)(`should report download path within page.on('download', …) handler for Blobs`, async({browser, server}) => {
|
||||
const page = await browser.newPage({ acceptDownloads: true });
|
||||
const onDownloadPath = new Promise((res) => {
|
||||
page.on('download', dl => {
|
||||
dl.path().then(res);
|
||||
});
|
||||
});
|
||||
await page.goto(server.PREFIX + '/download-blob.html');
|
||||
await page.click('a');
|
||||
const path = await onDownloadPath;
|
||||
expect(fs.readFileSync(path).toString()).toBe('Hello world');
|
||||
await page.close();
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user