0

I want to verify file download using NodeJS and Webdriverio. The file to download is of PDF format. When WebDriverIO clicks on "Download" Firefox opens up the following download confirmation window:download confirmation pop-up

I want Firefox to download the file automatically without showing above confirmation window, so I used the below code:

 conf_firefox.js file
require('dotenv').config();
const path = require('path');
const merge = require('deepmerge');
const baseConfig = require('./wdio.conf_base');

exports.config = merge(baseConfig.config, {
  services: ['selenium-standalone'],
  capabilities: [
    {
      maxInstances: 2,
      browserName: 'firefox',
      'moz:firefoxOptions': {
        prefs: {
          'browser.download.dir': path.join(__dirname, '../test-data/tmp/download/firefox'),
          'browser.helperApps.neverAsk.saveToDisk': 'application/pdf',
        },
      },
      acceptInsecureCerts: true,
    },
  ],
});

but still Firefox shows the same window. How can I set Firefox profile so that PDF files are downloaded automatically without showing the confirmation dialogue? For chrome everything works correctly. Thanks!

  • Try adding following lines to perfs -> 'browser.helperApps.alwaysAsk.force' : false 'browser.download.manager.showWhenStarting' : false – Nitin Sahu Nov 29 '21 at 22:12
  • @NitinSahu unfortunately but it didn't help :( – Gintars Lazda Nov 30 '21 at 06:44
  • It's strange that It's not working. I just came across this link https://stackoverflow.com/questions/23800195/auto-download-pdf-in-firefox You may try if this solves your problem – Nitin Sahu Nov 30 '21 at 08:58
  • @NitinSahu found solution : just add 'pdfjs.disabled': true and instead of application/json used application/octet-stream – Gintars Lazda Nov 30 '21 at 09:38

2 Answers2

1

This cap works for me:

{
  browserName: "firefox",
  "moz:firefoxOptions": {
    prefs: {
      "browser.download.dir": downloadDir,
      "browser.download.useDownloadDir": true,
      "browser.helperApps.alwaysAsk.force": false,
      "browser.helperApps.neverAsk.saveToDisk": "application/pdf,image/jpeg,image/jpg,text/calendar,text/csv",
      "pdfjs.disabled": true,
    },
  },
}
unickq
  • 1,497
  • 12
  • 18
0

Found a solution: Just added 'pdfjs.disabled': true and instead of application/json, used application/octet-stream.

browserName: 'firefox',
      'moz:firefoxOptions': {
        prefs: {
          'browser.download.dir': path.join(__dirname, '../test-data/tmp/download/firefox'),
          'browser.download.folderList': 2,
          'browser.helperApps.neverAsk.saveToDisk': 'application/octet-stream',
          'pdfjs.disabled': true,
        },
      },
ouflak
  • 2,458
  • 10
  • 44
  • 49