Home > Net >  Download files automatically through firefox with nodeJS and webdriverio
Download files automatically through firefox with nodeJS and webdriverio

Time:11-30

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!

CodePudding user response:

Found solution : just add 'pdfjs.disabled': true and instead of application/json used application/octet-stream

CodePudding user response:

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