Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
tests(downloads): add a test for Blob downloads (#1936) (#1939)
Ross Wollmandc23c567c4d5
diff --git a/test/assets/download-blob.html b/test/assets/download-blob.htmlnew file mode 100644index 0000000000..02a08893b5--- /dev/null+++ b/test/assets/download-blob.html@@ -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>diff --git a/test/download.spec.js b/test/download.spec.jsindex 995b3c5961..f160ec6a94 100644--- a/test/download.spec.js+++ b/test/download.spec.js@@ -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();})