Search code examples
javascriptwebdriver-io

How to set preference for downloading .dmg file using WebdriverIO?


I want to download a .dmg file using webdriverIO and when the link has been clicked the file download popup pops out which is a .dmg file. How can I handle the popup which asks "save" or "cancel"?


Solution

  • If the problem is the save popup, then you can avoid the popup by setting the default download location for the browser.

    For CHROME:

    In the wdio.conf.js file, in capabilities add the following:

    Note: Before adding make sure you have defined downloadDir with the default path where the file needs to be saved.

    capabilities: [{
        browserName: 'chrome',
        // this overrides the default chrome download directory with our temporary one
        goog:chromeOptions: {
          prefs: {
            'download.default_directory': downloadDir
          }
        }
      }]
    

    This code will set the default download directory and you will not see the pop up anymore.

    More information: https://blog.kevinlamping.com/downloading-files-using-webdriverio/