2

Here's my dilemma. I'm creating some automation tests using selenium web driver coding in Java. The main output of the software is to load a PDF in adobe acrobat.

I'm also using Jenkins which is why my problem has come about as I wont be able to physically see the output created by the software.

Is it possible to save this file in a certain location when the test has completed?

afcbpete
  • 51
  • 1
  • 1
  • 7
  • with the Selenium it is not possible to operate the browser menu. If your web site/page has some save-button you can use his via Selenium. Without more details, it is impossible to help on that, though. – Würgspaß Jun 18 '15 at 11:37
  • What kind of details do you require? – afcbpete Jun 18 '15 at 12:19
  • first of all: how is the PDF generated/loaded (i.e. what is the trigger)? Is there a pure page-driven way to save the file on disk (e.g. by clicking on some HTML element on the web page)? What does your test code actually do? Show use the snippet which opens the pdf. – Würgspaß Jun 18 '15 at 12:28
  • This then fires up a window asking to open file or save as from there the PDF will load or save depending on what you would press.
    – afcbpete Jun 18 '15 at 12:44
  • This http://ardesco.lazerycode.com/index.php/2012/07/how-to-download-files-with-selenium-and-why-you-shouldnt/ might be interesting to you. – SiKing Jun 18 '15 at 15:21
  • Cf. https://stackoverflow.com/a/48798425/1333493 https://stackoverflow.com/questions/26894071/chromedriver-selenium-automate-downloads – Nemo May 07 '18 at 09:54

1 Answers1

2

This works with Firefox:

Change the Firefox profile used by Selenium (better to create a dedicated profile as described here) via Tools -> Settings -> Applications and change action of file type PDF to "Save file".

In that case the window asking to open file or save will not show up and the file is quietly saved to configured directory (Settings -> General -> Downloads).

Remember that you have to do that locally and in Jenkins as well. In both cases WebDriver has to be told to use this Firefox profile using environment variable -Dwebdriver.firefox.profile on startup (if there is a custom profile otherwise default is used).

You can also set the profile programmatically. Here is an example in python and for CSV files but you should be able to transform that to Java and PDF.

Community
  • 1
  • 1
Würgspaß
  • 4,660
  • 2
  • 25
  • 41