1

Used userDataDir: 'path' in driver configure file but still files are not downloading in the specific location

Expected file to be downloaded in specific location Can someone help me how to setup a specific path to download file in Karate in chrome like in selenium Chrome preference

  • to be honest I don't know the answer. it would be great if you can do some research and post your findings as an answer to help others. many teams switch to downloading files via an API test, since it is simpler. my recommendation is you can skip testing this via the UI since it may be a waste of time if you can test the logic using the API: https://stackoverflow.com/a/53706294/143475 – Peter Thomas Nov 10 '22 at 17:24

1 Answers1

1

You could use the experimental Browser.setDownloadBehavior Chrome DevTools Protocol method.

Here is a full example:

Feature:

Background:
    * def waitForDownload = function(downloadPath) { while (!new java.io.File(downloadPath).isFile()) java.lang.Thread.sleep(1000) }

Scenario:
    * configure driver = { type: 'chrome' }
    * driver 'https://github.com/karatelabs/karate/releases/tag/v1.3.0' 
    * driver.send({ method: 'Browser.setDownloadBehavior', params: { behavior: 'allow', downloadPath: karate.toAbsolutePath('./someDir') } })

    # scroll to bottom of page to ensure download link is created
    * script('let x = (document.scrollingElement || document.body); x.scrollTop = x.scrollHeight')
    * waitFor("a[href='/karatelabs/karate/archive/refs/tags/v1.3.0.tar.gz']").click()

    * call waitForDownload karate.toAbsolutePath('./someDir/karate-1.3.0.tar.gz')
jckdnk111
  • 2,280
  • 5
  • 33
  • 43