Parasol icon indicating copy to clipboard operation
Parasol copied to clipboard

Add support to set the default download path for chrome

Open IwanVosloo opened this issue 5 years ago • 2 comments

Hi,

I have tried to manually set the default download path for chrome using a DesiredCapabilities object:

desiredDriverBrowserCapabilities
  ^ BPDesiredCapabilities chrome
"    setCapability: 'chromeOptions'  << also tried this"
    setCapability: 'goog:chromeOptions'
          to:
            (Dictionary new
                at: 'prefs'
                put:
                  (Dictionary new
                    at: 'download.default_directory'
                    put: '/tmp/testdownloads';
                    at: 'download.prompt_for_download'
                    put: false;
                    at: 'download.directory_upgrade'
                    put: true;
                    yourself);
          yourself);
    yourself

I could not get that to work. I suspect there are a lot of things related to the internals of WebDriver and chromedriver that I'd have to understand better.

If you trawl the web on the topic, you find a lot of references for setting this using the ChromeOptions object .

It would be super if such an object was available in Parasol or even if there was a bit of documentation for how to get this task done with what is available at present.

IwanVosloo avatar Jan 07 '19 06:01 IwanVosloo

I've put together a Java test based on the answers to the StackOverflow question:

Test Chrome Download Directory.zip

The output shows what is actually passed as desired capabilities:

    [junit] Testsuite: Tests
     [exec] 11:44:48.413 INFO [ActiveSessionFactory.apply] - Capabilities are: {
     [exec]   "browserName": "chrome",
     [exec]   "goog:chromeOptions": {
     [exec]     "args": [
     [exec]     ],
     [exec]     "extensions": [
     [exec]     ],
     [exec]     "prefs": {
     [exec]       "profile.default_content_settings.popups": 0,
     [exec]       "download.default_directory": "\u002fvar\u002ffolders\u002frv\u002f5k6p15048xj49y001s63pbbh0000gn\u002fT\u002ftestDownloadDirectoryOption5398117482515693748"
     [exec]     }
     [exec]   }
     [exec] }
…
    [junit] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 10.373 sec

I haven't tried it in Pharo yet, but maybe this helps you figure it out? Note that for download.default_directory, the path separator seems to get encoded as \u002f; maybe that has something to do with it?

Rinzwind avatar Jan 07 '19 10:01 Rinzwind

Thanks for replying... my problem turned out to be in my own code that was using the above correct code incorrectly. So what I posted above actually DOES work.

Some notes for future reference:

  • Different answers on stack overflow suggest setting a number of preferences together with the download directory, and the answers differ. For me setting only "download.default_directory" was sufficient. (Perhaps I still have to encounter more corner cases?)
  • I did not have to encode the directory itself in any special way.
  • I am a bit confused as to whether to use "chromeOptions" vs "goog:chromeOptions". The latter is what is used in java code, but from the use here I gathered "chromeOptions" also works. According to my experiments both work.

IwanVosloo avatar Jan 08 '19 06:01 IwanVosloo