SeasideSt / Parasol

Testing web apps in Smalltalk using Selenium WebDriver.
MIT License
31 stars 16 forks source link

Add support to set the default download path for chrome #27

Open IwanVosloo opened 5 years ago

IwanVosloo commented 5 years ago

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.

Rinzwind commented 5 years ago

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?

IwanVosloo commented 5 years ago

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: