Protractor - Jasmine - Download file to a relative

2019-07-12 16:35发布

问题:

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?

回答1:

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