From f469b8ec133e0eb003acba1c26bc47c6596e3eee Mon Sep 17 00:00:00 2001 From: Ivan Krutov Date: Sat, 26 Oct 2019 13:14:23 +0300 Subject: [PATCH] Added code snippets about downloading files (fixes #743) --- docs/file-download.adoc | 57 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/docs/file-download.adoc b/docs/file-download.adoc index efa8c0f1..677a2fe8 100644 --- a/docs/file-download.adoc +++ b/docs/file-download.adoc @@ -1,8 +1,59 @@ -== Accessing Files Downloaded with Browser +== Downloading Files From Browser + +=== Downloading Files in Different Browsers + +==== Chrome + +.Downloading files with Java +[source,java] +---- +ChromeOptions chromeOptions = new ChromeOptions(); +chromeOptions.setExperimentalOption("prefs", new HashMap(){ + { + put("profile.default_content_settings.popups", 0); + put("download.default_directory", "/home/selenium/Downloads"); + put("download.prompt_for_download", false); + put("download.directory_upgrade", true); + put("safebrowsing.enabled", false); + put("plugins.always_open_pdf_externally", true); + put("plugins.plugins_disabled", new ArrayList(){ + { + add("Chrome PDF Viewer"); + } + }); + } +}); + +WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), chromeOptions); +driver.navigate().to("http://example.com/myfile.odt"); +---- + +==== Firefox + +.Downloading files with Java +[source,java] +---- +FirefoxOptions firefoxOptions = new FirefoxOptions(); +firefoxOptions.setCapability("moz:firefoxOptions", new HashMap(){ + { + put("prefs", new HashMap(){ + { + put("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream"); + } + }); + } +}); + + +WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), firefoxOptions); +driver.navigate().to("http://example.com/myfile.odt"); +---- + +=== Accessing Files Downloaded with Browser [NOTE] ==== -. This feature only works when browsers are run in containers. +. This feature only works when browsers are being run in containers. . Files are accessible only when browser session is running. ==== @@ -10,4 +61,4 @@ Your tests may need to download files with browsers. To analyze these files a co ``` http://selenoid-host.example.com:4444/download/f2bcd32b-d932-4cdc-a639-687ab8e4f840/myfile.txt ``` -In order for this feature to work an HTTP file server should be listening inside browser container on port `8080`. Download directory inside container to be used in tests is usually `~/Downloads`. \ No newline at end of file +In order for this feature to work an HTTP file server should be listening inside browser container on port `8080`. Download directory inside container to be used in tests is usually `~/Downloads`.