AquariusPotter
AquariusPotter

Reputation: 156

Protractor Firefox download file

I have problem with download excel file with protractor in firefox. I set protractor config file with

{
  browserName: 'chrome',
  acceptInsecureCerts: true,
  chromeOptions: {
    args: [
      "--headless",
    ],
    prefs: {
      'download': {
        'prompt_for_download': false,
        'directory_upgrade': true,
        'default_directory': process.cwd() + "/resources/test/download",
      },

    },
  },
}

i run perfect with chrome, but when i set with firefox :

{
  browserName: 'firefox',

  acceptInsecureCerts: true,
  'moz:firefoxOptions': {
    args: [
      "--headless"
    ],
    prefs: {
      'download': {
        'prompt_for_download': false,
        'directory_upgrade': true,

        'default_directory': process.cwd() + "/resources/test/download",

      },
    },
  },
},

but firefox got error, i think firefox cant read the prefs of firefox . I think it's not working firefox. how can i fix to run with firefox ? When i comment "--headless" and i run protractor with firefox , firefox shown me 'save as' dialog. i think it's error reason ? Right? Can somebody help me ?

Upvotes: 1

Views: 635

Answers (1)

AquariusPotter
AquariusPotter

Reputation: 156

This is solution for the question!

{
 browserName: 'firefox',
 marionette:true,
 acceptInsecureCerts: true,
 'moz:firefoxOptions': {
   args: [
     "--headless"
   ],
   prefs: {
     'browser.download.folderList' : 2,
     'browser.download.dir' : process.cwd() + "/resources/test/download",
     'services.sync.prefs.sync.browser.download.useDownloadDir' : true,
     'browser.download.useDownloadDir' : true,
     'browser.download.manager.alertOnEXEOpen' :false,
     'browser.download.manager.closeWhenDone':true,
     'browser.download.manager.focusWhenStarting' : false,
     'browser.download.manager.showWhenStarting' : false,
     'browser.helperApps.alwaysAsk.force':false,
     'browser.download.manager.showAlertOnComplete':false,
     'browser.download.manager.useWindow':false,
     'browser.helperApps.neverAsk.saveToDisk' : 'text/plain,text/csv,application/csv;text/comma-separat‌​ed-values;application/excel;application/octet-stream;application/xlsx;application/xls;application/vnd.ms-excel;application/vnd.ms-excel.addin.macroenabled.12;application/vnd.ms-excel.sheet.binary.macroenabled.12;application/vnd.ms-excel.template.macroenabled.12;application/vnd.ms-excel.sheet.macroenabled.12;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
         },
 },

},

{
  browserName: 'chrome',
  acceptInsecureCerts: true,
  chromeOptions: {
    args: [
      "--headless",
    ],
    prefs: {
      'download': {
        'prompt_for_download': false,
        'directory_upgrade': true,
        'default_directory': process.cwd() + "/resources/test/download",
      },

    },
  },
}

We can get firefox's prefs in the link : https://developer.mozilla.org/en-US/docs/Archive/Mozilla/Download_Manager_preferences

and get mine types of firefox (type of download file in firefox) in the link https://www.freeformatter.com/mime-types-list.html

Upvotes: 1

Related Questions