1

I've been trying to update my conf.js file to download files, it should work for firefox and chrome (independent of one another).

I've been following the guides and answers online, (including but not limited to stackoverflow) yet it doesn't fully work for me. Chrome is no problem, firefox is my trouble maker.

On firefox it simply does not download the file, unlike chrome where it downloads the file.

Update: I cannot disable popup from firefox

The relevant info from conf.js

exports.config = {
[...]
 multiCapabilities: [
    {
      browserName: 'chrome',
      'goog:chromeOptions': {
        w3c: false, // problems with latest chrome driver... browser.actions is causing issues: https://github.com/jan-molak/serenity-js/issues/329
        prefs: {
          download: {
            prompt_for_download: false,
            directory_upgrade: true,
            default_directory: downloadsPath,
          },
        },
      },
    } , 
    {
      browserName: 'firefox',
      'goog:chromeOptions': {
        marionette: true,
        'moz:firefoxOptions': {
          prefs: {
            'pdfjs.disabled': true,
            'browser.download.folderList': 2,
            'browser.download.dir': downloadsPath,
            'browser.download.panel.shown': false,
            'browser.download.useDownloadDir': true,
            'browser.download.manager.useWindow': false,
            'browser.helperApps.alwaysAsk.force': false,
            'browser.helperApps.neverAsk.openFile': true,
            'browser.download.manager.closeWhenDone': false,
            'browser.download.manager.alertOnEXEOpen': false,
            'browser.download.manager.showWhenStarting': false,
            'browser.download.manager.focusWhenStarting': false,
            'browser.download.manager.showAlertOnComplete': false,
            'browser.helperApps.neverAsk.saveToDisk': 'application/vnd.openxmlformats',
          },
        },
      },
    },
  ],
[...]
};

The relevant code from my dowload-e2e.js spec:

    const downloadBtn = manipulations.getDomObject('download-contract-button', 'id');
    browser.executeScript('arguments[0].click();', downloadBtn.getWebElement());

    try {
      await downloads.verifyFileExists(`file-name.docx`);
      await downloads.verifyFileSize(`file-name.docx`, 0);
    } catch (err) {
      throw new Error(`ERROR: ${err.message}`);
    }
    downloads.removeFile(`file-name.docx`);
Gabson
  • 55
  • 12

1 Answers1

2

Firefox/Chrome try like this:

const multiCapabilities = [
{
    browserName: 'chrome',
    'goog:chromeOptions': {
        w3c: false, // due problems with latest chrome driver
                    // browser.actions is causing issues: https://github.com/jan-molak/serenity-js/issues/329
        prefs: {
            download: {
                'prompt_for_download': false,
                'directory_upgrade': true,
                'default_directory': downloadsPath
            }
        }
    }
},
{
    browserName: 'firefox',
    'goog:chromeOptions': {
        marionette: true,
        'moz:firefoxOptions': {
            prefs: {
                'browser.download.folderList': 2,
                'browser.download.dir': downloadsPath,
                'browser.download.manager.showWhenStarting': false,
                'browser.helperApps.alwaysAsk.force': false,
                'browser.download.manager.useWindow': false,
                'browser.helperApps.neverAsk.saveToDisk':   'application/octet-stream, application/json, ' +
                                                            'text/comma-separated-values, text/csv, application/csv, ' +
                                                            'application/excel, application/vnd.ms-excel, ' +
                                                            'application/vnd.msexcel, text/anytext, text/plaintext, ' +
                                                            'image/png, image/pjpeg, image/jpeg, application/zip'
            }
        }
    }
}

];

Infern0
  • 2,565
  • 1
  • 8
  • 21
  • thanks for the hint with chrome, but will this fix the firefox problem with downloading a file? – Gabson Apr 27 '20 at 11:56
  • i didnt understand you, this is a setup for chrome as you requested, firefox capability is another object. – Infern0 Apr 27 '20 at 12:04
  • The title says firefox and chrome, I have mentioned firefox and chrome in the description. I have provided my code, which doesn't fully work, to ask what's wrong with it. I did specifiy what my troubles are – Gabson Apr 27 '20 at 12:08
  • added firefox solution also – Infern0 Apr 27 '20 at 12:22
  • 1
    i have done test on https://www.thinkbroadband.com/download and it download the file, please give info what content you are trying to download or something additional for the website or result yo uare trying to achive. This is a working configuration but for some rason it doesnt work for you, in that case any additional info will be good. – Infern0 Apr 27 '20 at 13:05
  • ok sorry, then something must be wrong with my waits I assume... if this works for you then I will fix my spec. Thank you for your help – Gabson Apr 27 '20 at 13:09
  • hey, for some reason I cannot disable the 'download file popup' from firefox. I've update my original post accordig to what you suggested. Do you mind seeing what might be wrong? I have adjusted the mime-type to the content type of the file to be downloaded – Gabson Apr 28 '20 at 11:48
  • @Gabriel append the mime type to parameter "browser.helperApps.neverAsk.saveToDisk" here is the list of file types and the mime type representation https://stackoverflow.com/questions/4212861/what-is-a-correct-mime-type-for-docx-pptx-etc in your case for .docx, you need to append "application/vnd.openxmlformats-officedocument.wordprocessingml.document" – Infern0 Apr 28 '20 at 12:31