How do I programmatically set the download path in Protractor?

I am trying to dynamically set the Chrome download path in conf.js for Protractor. Our web service is exporting a file and I am writing a test that needs to know where the file will be loaded in order to test it. Right now I am having a hard time setting the browser load path. The problem is that other members of my team and build machines will run this test as well, and there is not a single boot path I can choose that will work on every dev and build machine. After some reading, I thought the best solution would be to get the user data directory from the getCapabilities () function inside the onPrepare function, and then set that as the download directory, like this:

onPrepare: function () {
    var jasmineReporters = require('jasmine-reporters');
    jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter( { 
        savePath: 'reports', consolidateAll: true } ));
    var cap = browser.getCapabilities();
    // Set prefsDict using cap.caps_.userDataDir
},
capabilities: {
    'chromeOptions': {
        'prefs': prefsDict
    }
}

      

This will allow the code to be dynamic, but getCapabilities returns a promise, so the above code won't work because conf.js will finish creating the config object before the promise is decided. Using the then function in getCapabilities does not help because I cannot build the capabilities section of my config object in the then function. I cannot call getCapabilities outside of the onPrepare function because conf.js has no context for it. Network path setting is also not possible for command setting.

Has anyone else done something similar? Is there any other way to programmatically set the download path for Chrome?

+3


source to share


1 answer


This probably won't solve the problem in the way you would like, but you can run

protractor conf.js --capabilities.chromeOptions.prefs 'path/to/user/folder'

      

if the user is smart enough to know, find or store this information.




Edit:

You might be able to use .execute()

it to force browser.getCapabilities();

execute before moving on to the next statement.

Usually called protractor.promise.controlFlow().execute( myPromise )

However, I think it execute()

also returns a promise, so you can get back to the square with this idea.

0


source







All Articles