Created
July 18, 2019 08:35
-
-
Save AlexKamaev/8c1eb8a5fb638fa366b44447f6d7c5a4 to your computer and use it in GitHub Desktop.
Enable file downloading for Headless Chrome using TestCafe internal API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import path from 'path'; | |
import { Selector } from 'testcafe'; | |
async function enableDownloadForHeadlessChrome (t) { | |
const browserConnection = t.testRun.browserConnection; | |
const client = browserConnection.provider.plugin.openedBrowsers[browserConnection.id].client; | |
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') | |
}); | |
} | |
fixture`test` | |
.page`https://github.com/DevExpress/testcafe/`; | |
test('test', async t => { | |
await enableDownloadForHeadlessChrome(t); | |
await t.click(Selector('summary').withText('Clone or download')); | |
await t.click(Selector('a').withText('Download ZIP')); | |
//NOTE: please replace with string with your function which detects that the file exists | |
await t.wait(60000); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
await browser.browserClient.getActiveClient();
returns undefined.