Downloading a file from a website (any, really) to ${process.env.HOME}/Downloads and checking the contents.
Download works with chromium gui on linux, but fails with chromium:headless. Screenshot after clicking the download link show just the download page but no statusbar with download in progress. The loop waiting for the file to be complete takes forever, there is no file in ${process.env.HOME}/Downloads.
File is downloaded. Additionally, I'd expect tests to behave identically in headles or GUI mode.
My full code is at https://github.com/TauPan/Tageblatt-Downloader however the download would only work with my login data. I assume that the problem can be reproduced with any site offering a download.
Maybe it can be fixed with a configuration.
My full code is at https://github.com/TauPan/Tageblatt-Downloader however the download would only work with my login data. I assume that the problem can be reproduced with any site offering a download.
Sorry for the delay. I researched the issue and found that downloading in headless mode could be implemented via Chrome Debug Protocol.
Please refer to the following links to get started:
Chrome DevTools Protocol
chrome-remote-interface package
chrome-remote-interface repo
I've prepared the following workaround:
const path = require('path');
const CDP = require('chrome-remote-interface');
import { Selector } from 'testcafe';
fixture `test`
聽 聽 .page `https://github.com/DevExpress/testcafe/`;
test('test', async t => {
聽 聽 const client 聽 聽 聽 聽 聽 聽= await CDP();
聽 聽 const { Network, Page } = client;
聽 聽 await Promise.all([
聽 聽 聽 聽 Network.enable(),
聽 聽 聽 聽 Page.enable()
聽 聽 ]);
聽 聽 Network.requestWillBeSent((param) => {
聽 聽 聽 聽 console.log("Network.requestWillBeSent: " + JSON.stringify(param));
聽 聽 });
聽 聽 Network.responseReceived((param) => {
聽 聽 聽 聽 console.log("Network.responseReceived: " + JSON.stringify(param));
聽 聽 });
聽 聽 await Page.setDownloadBehavior({
聽 聽 聽 聽 behavior: 'allow',
聽 聽 聽 聽 downloadPath: path.resolve(__dirname, 'downloaded')
聽 聽 });
聽 聽 await t.click(Selector('summary').withText('Clone or download'));
聽 聽 await t.click(Selector('a').withText('Download ZIP'));
聽 聽 await t.wait(20000) // please replace with string with your function which detects that the file exists
})
This test navigates to the TestCafe repository and downloads the .zip archive. You should use the following command to start the test: node bin/testcafe "chrome:headless:cdpPort=9222" test.js. Here I define the cdp port that is used by the CDP module by default.
Note that it is hard to predict what unexpected results this workaround can produce, and I suggest that you carefully check this prior to integrating this solution into your project.
We will consider integrating this feature to TestCafe.
While this works great for chrome:headless - is there anything similar for firefox:headless? @AlexKamaev
Quick note (see https://github.com/DevExpress/testcafe/issues/3600 for more information): If you specify the cdpPort manually, you should not run in concurrent-mode since this will lead to errors. So while this workaround allows you to download files, it will not allow you to run concurrently
I've modified my example a little. Now it will allow you to use the concurrency option. Please refer to https://gist.github.com/AlexKamaev/8c1eb8a5fb638fa366b44447f6d7c5a4
This example is using an internal TestCafe API. It works stable, however, it can change in the future
This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.
Most helpful comment
Sorry for the delay. I researched the issue and found that downloading in headless mode could be implemented via Chrome Debug Protocol.
Please refer to the following links to get started:
Chrome DevTools Protocol
chrome-remote-interface package
chrome-remote-interface repo
I've prepared the following workaround:
This test navigates to the TestCafe repository and downloads the .zip archive. You should use the following command to start the test:
node bin/testcafe "chrome:headless:cdpPort=9222" test.js. Here I define the cdp port that is used by the CDP module by default.Note that it is hard to predict what unexpected results this workaround can produce, and I suggest that you carefully check this prior to integrating this solution into your project.
We will consider integrating this feature to TestCafe.