I have a test in NodeJS that downloads a file from a website using Google Chrome on the cloud (BrowserStack). I am trying to download the file to a directory in my project. I understand I have to set this via Chrome Options but no answers posted here to seem work.
Could someone please share an example how this is done using NodeJS? Below is one example I have tried that doesn't work.
module.exports.createChromeDriver = async function () {
if (parameters.runOnCloud === true) {
await filesDirectory.createAppDirIfRequired(paths.tempDir, paths.downloadDirName);
let capabilities = {
'name' : parameters.report,
'browserName' : 'Chrome',
'browser_version' : '79.0',
'os' : 'OS X',
'os_version' : 'Mojave',
'resolution' : '1920x1080',
'browserstack.user' : credentials.browserstack.user,
'browserstack.key' : credentials.browserstack.key,
'browserstack.local' : 'true',
'browserstack.localIdentifier': parameters.bsLocalIdentifier,
'browserstack.networkLogs' : 'false',
}
if (parameters.tests === "wallet-web") {
capabilities['browserstack.networkLogs'] = 'true';
}
let options = new chrome.Options();
const prefs = {'download.default_directory' : paths.downloadsDir};
options.addArguments('prefs', prefs);
options.merge(capabilities);
let driver = await new Builder().
usingServer('http://hub-cloud.browserstack.com/wd/hub').
withCapabilities(capabilities).
build();
return driver;
}