2

I've read and follow the below questions here and its comments/answers:

Question 1

Question 2

Question 3

But could not find a way not to use absolutePath, since I need to have this tests run on another machine, so, I need to be relative to the project no the other folder outside of it. how can I accomplish that?

Community
  • 1
  • 1
Bruno Soko
  • 624
  • 6
  • 20
  • This topic will surely help: https://stackoverflow.com/questions/27922587/setting-chromedriver-preferences-on-protractor-tests – mr_penz Jan 17 '19 at 19:00

1 Answers1

10

As explained in the questions you have quoted, You can control where the file downloads using the below option

'chromeOptions': {
       prefs: {
        download: {
          'prompt_for_download': false,
          'default_directory': <<absolutePath>>
        }
      }
    }

Coming to your question on how to accomplish this when running on different machines, the answer is - Generate absolute Path from relative path and pass it onto Chrome Options.

var path = require('path');
var downloadsPath = path.resolve(__dirname, './downloads');
................
'chromeOptions': {
           prefs: {
            download: {
              'prompt_for_download': false,
              'default_directory': downloadsPath
            }
          }
        }
AdityaReddy
  • 3,625
  • 12
  • 25
  • Thanks! this resolved the issue that I was having, plus other, because I didn't mention, that I later needed to read from the downloaded file to compare it against another value! – Bruno Soko Mar 03 '17 at 02:03