Gintars Lazda
Gintars Lazda

Reputation: 49

Download files automatically through firefox with nodeJS and webdriverio

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!

Upvotes: 0

Views: 816

Answers (2)

Gintars Lazda
Gintars Lazda

Reputation: 49

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,
        },
      },

Upvotes: 0

unickq
unickq

Reputation: 3360

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,
    },
  },
}

Upvotes: 1

Related Questions