1

When PDF hyperlinks selected using karate chromedriver, the files are opening in new tab rather than downloaded to the local system. I tried with below ChromeOptions while configuring the driver, but none of them looks worked for me.

karate.configure('driver;, {type:'chromedriver', executable: path, webDriverSession:{desiredCapabilities:{browserName:'chrome', "goog:chromeOptions":{"prefs": {"pdfjs.disabled": true}}}}});

Below preferences also did not work.

"prefs": {"plugins.always_open_pdf_externally": true,"plugins.plugins_disabled", "Chrome PDF Viewer"}

I went through karate docs but couldn't find a similar topic. I really appreciate if anyone can help me with this issue or guide me to the documentation.

3 Answers3

1

Downloading files via WebDriver happens to be listed among their worst practices. The recommendation is to just get the URI from the DOM and use whatever http client you have available.

Matthias Winkelmann
  • 15,870
  • 7
  • 64
  • 76
1

Thanks Peter & Matthias for the idea. I am able to download the file after updating the element DOM structure using JavaScript.

var lnkName = element.attribute['href'];
script("document.getElelmentById('pageLinks').setAttribute('download','"+lnkName+"');");
element.click();
krmogi
  • 2,588
  • 1
  • 10
  • 26
0

I strongly suggest that in this case you just get the hyperlink of the PDF and use the Karate API testing functionality to download the file anywhere you want. You can find tips here: How to get the downloaded xlsx file from the api endpoint in karate? - and also look at the "upload.feature" example in the Karate demos.

If you need to execute some JS to get the final URL of the file, that is quite possible: https://stackoverflow.com/a/60800181/143475

Otherwise you need to continue doing some research, I don't know the answer and hopefully you can contribute your findings back.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248